applescript: toggle Notification Centre (Yosemite)

Notifications Center

Ever since Apple introduced Notification Centre, scripting it has been anything but easy.

I’ve seen brutal shell scripts and a variety of GUI scripts that variously work in Mountain Lion and Mavericks to turn ‘Do Not Disturb’ on and off. With Yosemite, Apple made yet another change to the ui process that controls Notification Centre, which means scripts like this one will choke.

If you’re wondering how to simply toggle whether Notification Centre is enabled or not with AppleScript on Yosemite, here’s the trick (whether this will continue to work in 10.11 is anyone’s guess** — see the comments below for the El Capitan version).

Enjoy it while it lasts! 🙂

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

About philastokes

Freelance Writer, Developer and Technical Communicator. Explaining the unexplainable with images, video and text. Scripting anything imaginable in Applescript, Bash, C, Objective C, Cocoa, Python and Xcode.

Posted on December 10, 2014, in AppleScript and tagged , , , , . Bookmark the permalink. 6 Comments.

  1. Hello! Cool script 🙂

    I was trying to run it at El Capitan 10.11.06 (the comments version) and it does not work.
    Is it still working for you?

  2. Unfortunately it does not work in 10.11. Has someone a working solution for El Capitan, please?

    • Yeah, it does, but you need to create a space in the two “NotificationCenter” words to read “Notification Center”. Looks like they changed it to make it more consistent. Here’s the full script for 10.11:


      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

%d bloggers like this: