Skip to content

Instantly share code, notes, and snippets.

@Zettt
Created September 18, 2014 13:08
Show Gist options
  • Save Zettt/fd9979100d4603e548d6 to your computer and use it in GitHub Desktop.
Save Zettt/fd9979100d4603e548d6 to your computer and use it in GitHub Desktop.
Toggle Notification Center's Do Not Disturb on OS X Yosemite. Brought to you by Automator.
-- Toggle Notification Center's DND on Yosemite
tell application "System Events"
option key down
delay 0.1
try
click menu bar item "Notification Center" of menu bar 2 of application process "SystemUIServer"
end try
try
click menu bar item "NotificationCenter, Do Not Disturb enabled" of menu bar 2 of application process "SystemUIServer"
end try
option key up
end tell
@raddougall
Copy link

Another variation to get El Capitan to work.....
from ... http://applehelpwriter.com/2014/12/10/applescript-toggle-notification-centre-yosemite/comment-page-1/

tell application "System Events"
    tell application process "SystemUIServer"
        try
            if exists menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 2 of application process "SystemUIServer" of application "System Events" then
                key down option
                click menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 2
                key up option
            else
                key down option
                click menu bar item "Notification Center" of menu bar 2
                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