7

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.

2
  • 1
    Do you already know about option-clicking the Notification Center icon in the corner of the menu bar?
    – Spiff
    Oct 28, 2013 at 23:48
  • Yea - I'd like to leave it ON but just have a keyboard shortcut to kill (or interact with, open/tab through their buttons) without the mouse/trackpad.
    – lioman
    Oct 29, 2013 at 3:07

3 Answers 3

8

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
3
  • OK, this works:tell application "System Events" tell process "NotificationCenter" click button "Close" of window 1 end tell end tell
    – Terry
    Oct 29, 2013 at 17:37
  • 1
    Is there a way to also nuke/kill BANNERS ahead of their automatic disappear (so the ones without a close button)?
    – lioman
    Oct 29, 2013 at 20:41
  • For dismissing notifications in 10.9 I just had to change "Close" to "OK".
    – dacc
    Nov 12, 2014 at 19:59
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.

3
  • Can't you change this to tell application "System Events" to close window 1 of process "NotificationCenter"? Haven't tried it, but I think close is also a valid action for a window.
    – Arne
    Oct 29, 2013 at 12:05
  • @Arne No, it shows an error that the window does not understand the close message. actions of window 1 returns just {action "AXPress" of window 1 of application process "NotificationCenter" of application "System Events"}, and there is no hidden close button shown by UI elements of window 1 or anything.
    – Lri
    Oct 29, 2013 at 12:13
  • Ok, too bad. Sometimes AppleScript is still a bit limited...
    – Arne
    Oct 29, 2013 at 13:35
0

I have an option, which uses Keyboard Maestro to run an Applescript and is detailed here: http://genuinecuriosity.com/unnotify

I have it mapped so that I hit [Command]+[Option]+[0] to clear all open alert dialogs.

Basically, I have created an Applescript to click the first button on all open alerts (typically Close), and does that until all alerts are cleared.

You can use the Applescript directly through Keyboard Maestro (as described in my article), or you can create a Service with Automator (this is a little more finicky due to Accessibility permissions requirements). The full Applescript is included in the article, along with a screen grab showing the setup in Keyboard Maestro.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .