AppleScript and Notification Center in Mavericks

⌃⌥⌘W is my work-mode toggle. That shortcut fires off a Keyboard Maestro workflow that does a number of things, from killing my email clients to setting all of my chat applications to do-not-disturb mode. If I’m already in work mode, pressing the shortcut again sets my chat status to Available and relaunches my email clients. I use it when going into and coming out of meetings, focused coding sessions, etc.

It also turns off all notifications by -clicking the Notification Center icon in the menu bar.1 Unfortunately, upgrading to Mavericks broke the Notification Center toggle, which is my favorite part of the workflow.

Here’s what the script used to look like:

tell application "System Events"
    tell process "Notification Center"
        key down option
        click first menu bar's first menu bar item
        key up option
    end tell
end tell

After a fair amount of digging, I managed to repair it. For some reason, click first menu doesn’t work anymore; click second menu does. Here’s the updated snippet:

tell application "System Events"
    tell process "Notification Center"
        key down option
        click second menu bar's first menu bar item
        key up option
    end tell
end tell

It’s a small tweak, but I couldn’t find it documented anywhere and discovered it through experimentation. Despite its relative obscurity, I rely on AppleScript quite a bit (and have for quite some time), which makes me wish for more thorough documentation–especially for weird changes like this.


  1. In case you didn’t already know, -clicking the icon in the top right corner of your screen disables all notifications for up to a day. You can re-enable them by -clicking the icon again.  ↩