applescript: toggle Notification Centre (Yosemite)
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
Posted on December 10, 2014, in AppleScript and tagged 10.10, AppleScript, Do Not Disturb, Notification Center, Yosemite. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0