Facebooktwittergoogle_plusredditpinterestlinkedinmail


With the release of Big Sur, my scripts for keyboard control of macOS notification alerts stopped working.

With a bit of experimentation and help from Google, I have written new ones.

Closing an alert

To close a notification alert on Big Sur, conceptually we want to press the X button that appears when you hover over it. The AppleScript to do this is:

This is much more complicated than just clicking button 1 of window 1 which is what we did before! In Big Sur, NotificationCenter now has a set of actions within the window and we iterate over them looking for the one called “Close” and then execute it.

This closes the notification alert.

Running from the command line

To run it from the command line, I have a file called close-alert stored in /usr/local/bin that runs osascript for me:

/usr/local/bin/close-alert:

This is marked as executable (chmod a+x /usr/local/bin/close-alert) so that I can close a notification alert from Terminal

Running from Alfred

I have also added to Alfred as a workflow. This requires two steps: a keyword step called “close alert” which takes no argument that is linked to a run script step which runs /usr/local/bin/close-alert.


This allows me to type “close alert” into Alfred to close the notification.


Alfred Close Alert

This gives me back keyboard control of closing the Big Sur notifcation alerts which is the operation I do most.