Skip to content

Instantly share code, notes, and snippets.

@Sanabria
Last active September 14, 2021 00:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Sanabria/40d80d84ec94644220489798f3aac930 to your computer and use it in GitHub Desktop.
Save Sanabria/40d80d84ec94644220489798f3aac930 to your computer and use it in GitHub Desktop.
Applescript: Toggle Do Not Disturb mode
(* 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
@dylan-chong
Copy link

dylan-chong commented Mar 9, 2019

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 with Centre

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 toggled

If anyone has found a solution it would be great to hear about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment