KISS

Keep It Simple Stupid

OSX: Close notification with keyboard

| comments

OS X’s UI looks nice, but isn’t very keyboard-friendly. For example, there is no standard shortcut to expand or minimize a window (yes, Cmd+M typically works, but it depends on the Window > Minimize menu command, which is sometimes not present). The same is true for the notification center, specifically calendar invitations/reminders that display a notification popup by default with two buttons: Close and Accept/Remind later. How do you dismiss it with the keyboard alone?

Luckily someone already came up with an AppleScript (another invention from apple) to click the first button on the notification. The source is on StackExchange; I’m reposting it here:

(close_notif.scpt) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
my closeNotif()
on closeNotif()

    tell application "System Events"
        tell process "NotificationCenter"
            set theWindows to every window
            repeat with i from 1 to number of items in theWindows
                set this_item to item i of theWindows
                try
                    click button 1 of this_item
                on error
                    my closeNotif()
                end try
            end repeat
        end tell
    end tell

end closeNotif

You can open this script in the Script Editor.app, select File > Export…, set “File Format:” to “Application”, save to e.g. ~/bin/. I use Alfred and don’t know if it’s the default or not, but after saving the “application”, it’s immediately available in Alfred. It’s very quick to open its window and type clo, in my case the first search result is the application.

One more note: on first launch, it’ll ask for accessibility to access other processes. You’ll need to go to System Preferences > Security & Privacy > Privacy > Accessibility, possibly unlock it with your password, and enable accessibility for close_notif.app.

It works well. Nevertheless, it is annoying that there is no standard way to do that in the system.

mac

Note: The comments in the blog are provided by disqus.com; if you don't see the comment form under the post, probably your browser or its extension (such as uBlock Origin or NoScript) blocks their scripts.

« Backups, TimeMachine, HFS and pain

Comments