Skip to content

Instantly share code, notes, and snippets.

@Sanabria
Last active September 14, 2021 00:00
Show Gist options
  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment