Genuine Curiosity

Author Dwayne Melancon is always on the lookout for new things to learn. An ecclectic collection of postings on personal productivity, travel, good books, gadgets, leadership & management, and many other things.

 

Close Multiple OS X Alerts With One Shortcut

If you're like me, sometimes you come back to your Mac screen and find a bunch of alerts hanging around on the screen - a collection of items ranging from "you didn't eject this disk properly!" warnings to calendar alerts, or alerts from other applications. Look familiar?

I know these alerts are meant to be helpful but when you're in a hurry (and sometimes there are many more than 4 of these), it can be annoying to through the process of clicking on each individual alert box to close them all. And, as far as I know, Apple doesn't provide a way to "mass approve" these alerts.

If that bugs you, too - I have a solution that lets you get rid of all the open alerts in one keyboard shortcut!

Applescript Is for Closers

Using a simple Applescript you can close all open items at once (note that it clicks the first button choice on each of these, so it will Close every alert - if there are any you want to Snooze, Accept, etc. make sure you do that before you run or automate this script).

Here is the script:

my closeNotif()
on closeNotif()
    
    tell application "System Events"
        tell process "Notification Center"
            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

This is pretty straight-forward and doesn't do anything scary - it simply automates clicking on the first button in each of the alerts until there are no more alerts on the screen.

Automation Is Your Friend

To make this really useful, we turn to automation, and there are a couple of options:

  • You can save this script as a file on your system, create an Automator Service that calls the script, and then assign a keyboard shortcut to run the Service through your computer's System Preferences. I won't describe the full process here, but you can find instructions for creating such a service elsewhere online.
    • Note: I tried this approach first, but found myself stumbling on a bunch of odd problems related to "Accessibility" permissions with Automator Services - they were a pain to work through.
  • My preferred option is to automate this with Keyboard Maestro, which is one of the most useful (and often under-rated) utilities I've ever used.

If you have Keyboard Maestro, the process is pretty easy - you just set up a workflow as seen below, and assign a hotkey to run it (I use Command-Option-0 because it is easy and doesn't conflict with anything on my system:

This is one of my most-used shortcuts - I hope you enjoy it!