Developing software in the Real World

Keyboard control of macOS notification alerts

I use Apple’s Reminders app to remind me about things that I need to do. It has the useful feature of syncing across my Mac, iPad and iPhone and I can add to it via Siri in my car. When I am notified on my Mac, a notification alert appears with two buttons: Complete and Later. Clicking Later offers a set of options to dismiss the alert and have it reappear in 5 minutes, in an hour, tomorrow or to never appear again:

Later menu

It has been a source of frustration to me that I cannot access these buttons using my keyboard, so I decided to solve this problem using AppleScript and Alfred.

Clicking the Complete button

To click the Complete button, we can use the following AppleScript:


In this code, we find the “Notification Center” process and click the first button of the first window. This will mark the reminder alert as complete. For other notifications, the first button is usually labelled Close, so we can close them too using the same script.

Clicking the Later button

The Later button too a bit more effort as its type is not button, but menu button. Once I discovered this, the same basic script works:


This will open the sub menu attached to the Later menu button and, most importantly, put the keyboard focus on it, so that I can then use the arrow keys to select the option I want and press return to action it.

Run from the terminal

To run an AppleScript from the terminal, we can use /usr/bin/osascript, so I created two bash scripts, close-alerts and open-alert-menu with executable rights:

/usr/local/bin/close-alert:


(As you can imagine, /usr/local/bin/open-alert-menu is essentially the same but clicks menu button 1 instead.)

Mapping to Alfred commands

For easy access to these scripts, I use custom Alfred workflows. There are easy to set up. On the Workflows tab

  • Create a new Keyword Input and set:
    1. Keyword to open alert menu with No Argument required
    2. Title to Open alert menu
  • Create a new Run Script Action and set the Script to /usr/local/bin/open-alert-menu

Repeat for close alert, and you end up with:

Alfred workflow

That’s it

I can now trigger Alfred and type open alert menu to enable me to control when I want to be re-reminded about an alert.

Alfred open alert menu

AppleScript is arguably my least favourite programming language as it tries to look like English and feels about as ambiguous. However, having a system-wide scripting system is quite useful!

3 thoughts on “Keyboard control of macOS notification alerts

  1. Thank you! I have been so confused about how to click the "Actions" button in Notification Center alerts. menu button works!

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *