Last active
September 14, 2021 00:00
-
-
Save Sanabria/40d80d84ec94644220489798f3aac930 to your computer and use it in GitHub Desktop.
Applescript: Toggle Do Not Disturb mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Note 1: The 1 after menu bar may need to be changed to 2 when using multiple monitors *) | |
(* Note 2: For 10.11 and newer “NotificationCenter” is now spelled “Notification Center”*) | |
tell application "System Events" | |
tell application process "SystemUIServer" | |
try | |
if exists menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 1 of application process "SystemUIServer" of application "System Events" then | |
(* It is disabled *) | |
display dialog "Notifications will be turned on" buttons {"Got it"} default button 1 | |
key down option | |
click menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 1 | |
key up option | |
else | |
(* It is enabled *) | |
display dialog "Notifications will be turned off" buttons {"Got it"} default button 1 | |
key down option | |
click menu bar item "Notification Center" of menu bar 1 | |
key up option | |
end if | |
on error | |
key up option | |
end try | |
end tell | |
end tell |
I got it fully working now on Catalina: https://apple.stackexchange.com/questions/419207/turn-do-not-disturb-on-or-off-in-an-applescript-app-macos-catalina/419213#419213
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem to work on mojave for me. But it does work on high sierra.
On mojave with british spelling,
Center
needs to be replaced withCentre
Also ,
key down option
seems to be ignored and the notification centre button on the menu bar gets clicked as if the option key was not down - and notification centre just gets opened, rather than do not disturb being toggledIf anyone has found a solution it would be great to hear about it