Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@ialexryan

This comment has been minimized.

Copy link

commented Aug 19, 2015

The ordering of the menu bars of SystemUIServer seems to be different on each person's computer. To avoid that, I wrote this:

    tell application "System Events"
        option key down
        delay 0.1
        tell application process "SystemUIServer"
            tell (every menu bar whose title of menu bar item 1 contains "Notification")
                click (1st menu bar item whose title contains "Notification")
            end tell
        end tell
        option key up
    end tell
end try```
@raddougall

This comment has been minimized.

Copy link

commented Jul 12, 2016

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
You can’t perform that action at this time.