Hileotech Posted May 31, 2016 Share Posted May 31, 2016 Hi, everybody! I was just wondering to find a way to create some "desktop modes" I can easily switch using shortcuts/hotkey/whatever. For instance, I created a "Presentation Mode" that 1) quits all opened app(s) 2) opens DevonThink Pro Office (my research database) 3) sends a notification (i.e.: "Presentation mode: ON") Basic, super-simple workflow, I know, but it just works! I would like to add a little more to this, by enabling "Do Not Disturb" (DND) when in "Presentation Mode" and disabling it when exiting this mode (I create a "Pure Desktop" mode that recreates desktop environment as after a reboot). I googled here and there, but I can't find a (working/reliable) solution. I found some (probably) working scripts, some terminal commands, etc. Is there anyone who successfully solved this? Any help? PS: I know I can bypass this, somehow, by selecting the appropriate option in System Preferences, but anyway I would like to be able to toggle "DND" on and off whenever I want through Link to comment
Hileotech Posted June 2, 2016 Author Share Posted June 2, 2016 Updates... Googling here and there I found this page from stackexchange: http://apple.stackexchange.com/questions/145487/how-to-enable-disable-do-not-disturb-from-shell-on-mavericks There are a couple of scripts/codes ready-to-use, but I have no idea on how to use them i Alfred. Anyone could help in this? Thanks! Link to comment
deanishe Posted June 2, 2016 Share Posted June 2, 2016 Use a Run Script action. If you're using a shell script (terminal commands), set Languages to /bin/bash, if you're using an AppleScript script, set Language to /usr/bin/osascript (AS). Link to comment
Hileotech Posted June 3, 2016 Author Share Posted June 3, 2016 (edited) Thanks, deanishe! I ended up doing like this: 1. I created an Apple Script file (named dnd.scpt) and saved in Documents ignoring application responses tell application "System Events" to keystroke "D" using {command down, shift down, option down, control down} end ignoring 2. I setup a keyboard shortcut in System Preferences according to the code above, shortcut that enables/disables (i.e. toggles) Notification Center 3. In Alfred workflow I created a new "Terminal Command" event, in which osascript /Users/**USERNAME**/Documents/dnd.scpt osascript -e "tell application \"System Events\" to keystroke \"q\" using command down" the last line simply asking Terminal to quit after doing its script call I'm quite satisfied with it, even because it's my very first workflow and I never coded before... Your suggestion really helped me! PS: next step: I don't want to simply change notification center status, but I would like to setup a status (on or off) for each mode I decide to activate... Hope to find a solution... Edited June 3, 2016 by Hileotech Link to comment
deanishe Posted June 3, 2016 Share Posted June 3, 2016 (edited) You don't need the Terminal Command. You can just paste your AppleScript into a Run Script Action with Language set to /usr/bin/osascript (AS). Or if you want to keep the separate script, paste your Terminal command into a Run Script Action with Language set to /bin/bash. Terminal Commands are for when you really want the code to execute visibly in a terminal, e.g. when you're starting a non-GUI application like rtorrent. Edited June 3, 2016 by deanishe Link to comment
juliosecco Posted June 4, 2016 Share Posted June 4, 2016 I'm quite satisfied with it, even because it's my very first workflow and I never coded before... Your suggestion really helped me! PS: next step: I don't want to simply change notification center status, but I would like to setup a status (on or off) for each mode I decide to activate... Hope to find a solution... Hi HileoTech, here some thoughts that I hope could help you go deeper on solving the problem so your problem is that you should know if notifications are activated or not, since you have only the way to toggle it on/off and viceversa but in 'blind' mode... now, assuming that you have an all day time interval set, from 00:00 to 23:59, so you are sure that notifications are activated every time the checkbox will be checked: you can see from the notifications preferences files if notifications are activated or not, the file is here: /Users/userName/Library/Preferences/ByHost/com.apple.notificationcenterui.LONG_STRING.plist obviously UserName and LONG_STRING will be different on your computer the preferences file contains a variable called doNotDisturb that strangely does not seems to change value setting notifications on/off, and is always false. BUT if notifications are activated, the file will contain two variables, dndStart and dndEnd, containing the start and end time for notifications. so if dndStart or dndEnd are set you can check if notifications are active, and the interval set. you can use a tool called PlistBuddy ( it was just deanishe pointing me on it some days ago ) to read the plist directly from terminal and so from an Alfred script using this string: /usr/libexec/PlistBuddy -c 'Print dndStart' /Users/userName/Library/Preferences/ByHost/com.apple.notificationcenterui.LONG_STRING.plist this command reads the dndStart property... hope this can be of some kind of use as a starting point... Giulio Link to comment
Hileotech Posted June 7, 2016 Author Share Posted June 7, 2016 Thanks deanishe and thanks juliosecco for your answers. I agree with deanishe: I used a separate script file just because I found different solutions for toggling Notification Center and it was easier for me to work on a separate file than to edit workflows. But this led me to use terminal and so to make my workflow heavier... Thanks for your suggestion! I'll investigate deeper with the "LONG_STRING" file. As far as I can imagine I just should ask Alfred to check IF dndStart and dndEnd exist THEN DoNotDisturb is "on", ELSE it's off... So my next step is to use this result as a variable in my workflow and ask Alfred to act consequently. Am I wrong, juliosecco? (Thanks for your hints!) Link to comment
Hileotech Posted June 7, 2016 Author Share Posted June 7, 2016 (edited) @ juliosecco: the I tried to run the PlistBuddy command you pointed me out (of course I modified it accordingly to my username and "LONGSTRING" thing), but the only thing I got from terminal was a Print: Entry, "dndStart", Does Not Exist both with Notification center on and off. I "quick-viewed" the "LONGSTRING" plist file, and I discovered that it does change according to Notification Center status. See this: Do Not Disturb OFF: after all the "xml version" etc code, <dict> <key>doNotDisturb</key> <false/> </dict> Do Not Disturb ON: again, after the "xml version" etc, <dict> <key>doNotDisturb</key> <true/> <key>doNotDisturb</key> <date>2016-06-07T07:46:16Z<date/> </dict> That's why running your command in terminal I just had a "Doesn't exist" answer... Anyway: I just have to ask Alfred to check if DND is "true" or "false"... Edited June 7, 2016 by Hileotech Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now