Ender Posted December 10, 2014 Posted December 10, 2014 Toggle Do Not Disturb The AppleScript used in the workflow posted here stopped working in Yosemite. I found a new AppleScript (on github) and updated the workflow accordingly. Download Workflow Subject22 1
Subject22 Posted December 10, 2014 Posted December 10, 2014 The AppleScript included in that workflow is a little unreliable. On my machine it will often execute both try blocks, causing Do Not Disturb to be toggled twice (effectively resetting it to whatever it was before I invoked the workflow). Here's an improved version without that issue. tell application "System Events" set toggled to false option key down delay 0.1 try click menu bar item "Notification Center" of menu bar 2 of application process "SystemUIServer" set toggled to true end try if not toggled then try click menu bar item "NotificationCenter, Do Not Disturb enabled" of menu bar 2 of application process "SystemUIServer" end try end if option key up end tell And here's the workflow.
Ender Posted December 10, 2014 Author Posted December 10, 2014 Interesting, I hadn't had that problem until I tried it today. I'm far from an AppleScript expert, so thanks for the new script
jsn117 Posted June 1, 2015 Posted June 1, 2015 Neither am I And no worries! Hey guys, thank you so much for working on this script. I've done the most recent changes in Mavericks (10.10.3) but it doesn't seem to work, is it still functioning for you? Cheers and thanks again!
frdmn Posted June 2, 2015 Posted June 2, 2015 Adjusted to make it work for non-US langauges: tell application "System Events" set toggled to false option key down delay 0.1 try click menu bar item "Notification Center" of menu bar 2 of application process "SystemUIServer" set toggled to true end try if not toggled then try click menu bar item 1 of menu bar 2 of application process "SystemUIServer" end try end if option key up end tell liatmgat 1
jsn117 Posted June 2, 2015 Posted June 2, 2015 Adjusted to make it work for non-US langauges: tell application "System Events" set toggled to false option key down delay 0.1 try click menu bar item "Notification Center" of menu bar 2 of application process "SystemUIServer" set toggled to true end try if not toggled then try click menu bar item 1 of menu bar 2 of application process "SystemUIServer" end try end if option key up end tell Still not working for me, anyone else having trouble?
sashaski Posted September 25, 2015 Posted September 25, 2015 None of these seem to work for me (on Yosemite 10.10.5). Would love to figure out how to fix it!
liatmgat Posted October 6, 2015 Posted October 6, 2015 That worked for me! (The multiple languages fix). Thank you so much! ~ No molestar ~ ~ Não perturbe ~ ~ Ne pas deranger ~ ))
forgetfulfellow Posted November 19, 2015 Posted November 19, 2015 Works fine for me on Yosemite 10.10.5
tabacitu Posted December 8, 2015 Posted December 8, 2015 Small opinionated update: - used the language fix above - change keywork to "dnd" - added a growl notification Credit goes to Ender. Thanks for the workflow! Download here.
sashaski Posted December 10, 2015 Posted December 10, 2015 Small opinionated update: - used the language fix above - change keywork to "dnd" - added a growl notification Credit goes to Ender. Thanks for the workflow! Download here. This works great, however I've noticed it doesn't work with the app Bartender been used. Any idea how to get it to work alongside it?
paulw Posted May 23, 2016 Posted May 23, 2016 I made a new version that checks whether Do Not Disturb is currently enabled, and lets you know which way you'll be toggling it. It then notifies you. No idea why it doesn't work with Bartender. If anyone has any suggestions for that problem or for improvements, by all means go ahead. https://github.com/paulrudy/alfred-toggle-do-not-disturb
liatmgat Posted May 26, 2016 Posted May 26, 2016 Thanks all! I did a ghetto workaround to make this work with Bartender - I just had the script quit Bartender at the beginning and then start it again at the end. It actually is surprisingly fast, so it seems like it will work for me until someone smart comes up with a real fix. (I adapted tabacitu's version because I thought it was faster.) Thank you paulw - I leave yours running too so I can tell from the Alfred results whether DND is off or on. But then I run tabacitu's version to toggle it. try tell application "Bartender 2" quit end tell end try tell application "System Events" set toggled to false option key down delay 0.1 try click menu bar item "Notification Center" of menu bar 2 of application process "SystemUIServer" set toggled to true end try if not toggled then try click menu bar item 1 of menu bar 2 of application process "SystemUIServer" end try end if option key up end tell tell application "Bartender 2" activate end tell sashaski 1
paulw Posted May 27, 2016 Posted May 27, 2016 (edited) liatmgat. you could also replace the script in the two "run script" sections (they're identical to each other except for one line: "delay 3") in my workflow with the script you prefer above. Edited May 27, 2016 by paulw
paulw Posted May 27, 2016 Posted May 27, 2016 Also, my version has a 3 second delay when turning Do Not Disturb ON, to allow for time to view the notification (otherwise, without the delay, there would be no notification, because Do Not Disturb would be on!). You can remove that delay in the script. You just wouldn't see a notification then.
sashaski Posted May 27, 2016 Posted May 27, 2016 Clever way of getting round that! Thanks Thanks all! I did a ghetto workaround to make this work with Bartender - I just had the script quit Bartender at the beginning and then start it again at the end. It actually is surprisingly fast, so it seems like it will work for me until someone smart comes up with a real fix. (I adapted tabacitu's version because I thought it was faster.) Thank you paulw - I leave yours running too so I can tell from the Alfred results whether DND is off or on. But then I run tabacitu's version to toggle it. try tell application "Bartender 2" quit end tell end try tell application "System Events" set toggled to false option key down delay 0.1 try click menu bar item "Notification Center" of menu bar 2 of application process "SystemUIServer" set toggled to true end try if not toggled then try click menu bar item 1 of menu bar 2 of application process "SystemUIServer" end try end if option key up end tell tell application "Bartender 2" activate end tell
squandre Posted July 21, 2016 Posted July 21, 2016 I made a new version that checks whether Do Not Disturb is currently enabled, and lets you know which way you'll be toggling it. It then notifies you. No idea why it doesn't work with Bartender. If anyone has any suggestions for that problem or for improvements, by all means go ahead. https://github.com/paulrudy/alfred-toggle-do-not-disturb I have tried every version of this and it doesn't seem to work. Running El Capitan 10.11.6 in Dutch.
paulw Posted July 23, 2016 Posted July 23, 2016 Check that Alfred has been enabled in System Preferences > Security & Privacy > Privacy > Accessibility. slappula 1
Jakub Sypiański Posted September 1, 2017 Posted September 1, 2017 None of these versions is working for me. Sierra 10.12.6 in Polish with Bartender 2.
Jkscx Posted October 25, 2017 Posted October 25, 2017 (edited) On 9/1/2017 at 2:58 PM, Jakub Sypiański said: None of these versions is working for me. Sierra 10.12.6 in Polish with Bartender 2. I tried making something myself and it works successfully on El Capitan 10.11.6 with Bartender 2. Should work on any Mac (with or without Bartender) as long as Apple doesn't change the Notification Center plist location (I think...). I got the code from this StackOverflow answer and converted it into a simple Alfred workflow. Here it is if you want to give it a try PS. It doesn't need to have Accessibility enabled which is a nice bonus. https://drive.google.com/file/d/0Bx3NCikqzbt5Qm1TdmkwQWFxUkU/view?usp=sharing Edited October 25, 2017 by Jkscx Additional info Jakub Sypiański 1
Jakub Sypiański Posted October 25, 2017 Posted October 25, 2017 1 hour ago, Jkscx said: I tried making something myself and it works successfully on El Capitan 10.11.6 with Bartender 2. Should work on any Mac (with or without Bartender) as long as Apple doesn't change the Notification Center plist location (I think...). Yey, it works, thank you so much, Jkscx!
paulw Posted October 7, 2018 Posted October 7, 2018 I updated my workflow from 2016, which notifies you beforehand whether DND is enabled or not, to use the defaults write method. It works in Mojave now, except that the notification center icon does not update. Working on finding a solution to that. Github link: https://github.com/paulrudy/alfred-toggle-do-not-disturb
karbassi Posted May 8, 2021 Posted May 8, 2021 For anyone looking for a working version for Big Sur (as of May 2021), I created a workflow that works. https://github.com/karbassi/alfred-toggle-do-not-disturb
paulw Posted May 8, 2021 Posted May 8, 2021 Nice work. Is there any way to update the menubar icon as well?
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