OSX Mavericks - keyboard shortcut to kill notifications
Is it possible to create a keyboard shortcut in OSX Mavericks to kill/hide notification center alerts (and speed up hiding banners that already disappear after some time automatically)?
EDIT: I used Terry's "nuke all" AppleScript (which has the added benefit of not throwing errors if notifications don't exist), saved to Documents and Compiled, then moved it to Library/Scripts/ and downloaded a free copy of FastScripts to assign a keyboard shortcut.
Solution 1:
This used to work:
tell application "System Events"
tell process "NotificationCenter"
click at {2500, 50}
end tell
end tell
But in Mavericks it gives me "System Events got an error: Can’t make {2500, 50} into type list." I finally found a fix, though:
tell application "System Events"
tell process "NotificationCenter"
click button "Close" of window 1
end tell
end tell
That closes the bottommost notification, which is good enough for me.
Also handy is this script to nuke 'em all:
tell application "System Events"
tell process "NotificationCenter"
set numwins to (count windows)
repeat with i from numwins to 1 by -1
click button "Close" of window i
end repeat
end tell
end tell
Solution 2:
You can use a script like this to click a notification:
tell application "System Events" to click window 1 of process "NotificationCenter"
It closes both banner and alert notifications that don't have a default action, but it performs the default action (like opening App Store for the "OS X Updates Available" notifications) if a notification has a default action.