Custom Apple Persistent Alerts with Actions: Alerter

I grew frustrated by AppleScript's unwillingness to provide access to the macOS functions and styles of Alerts.

For clarity, as far as the macOS Notification Center is concerned, Alerts are those notifications that remain on your screen and offer you options, dropdowns, and even text inputs which allow you to take actions. This is as opposed to regular AppleScriptable "notifications," which are Banners, have no functionality, and self-dismiss after a small time.

There used to be a unix binary called terminal-notifier which gave access to some the persistence functionality (didn't self-dismiss). I'd used it years ago but it got wonkier and wonkier. Last github update was 3 years ago. But the README on the terminal-notifier project page was updated and pointed me towards a complete gem. I searched the term here and didn't find anything. So, without further ado, I present…

ALERTER

This is a game-changer for me. Once downloaded and installed (as in just copy it there) in /usr/local/bin it's in the PATH and accessible via the command line. This allows us to create an entire branched workflow via a simple persistent alert that allows options, including the ability to type in a response. If all you want is a Notification that's going to stay in place, this will do it, but unlike the Keyboard Maestro built-in Notification, it does not halt subsequent steps until acted upon (unless your macro requires its input). So it can, at its simplest, just be a notification that you will not miss.

From the README…

alerter is a command-line tool to send Mac OS X User Alerts (Notifications), which are available in Mac OS X 10.8 and higher. (even catalina) the program ends when the alerter is activated or closed, writing a the activated value to output (stdout), or a json object to describe the alert event.>

Alerts are OS X notifications that stay on screen unless dismissed.>

2 kinds of alert notification can be triggered : "Reply Alert" or "Actions Alert"

I strongly encourage you to visit the project page and review it. I was able to refactor several macros to much more efficient workflows by enabling a dropdown menu of options and allowing the response (saved as a variable) to determine next steps.

Sample command:

alerter -message "Opening the Backup Manager now…" -title "Clear out old backups" -subtitle "It's safe to remove all but the latest." -appIcon /Applications/Transmit.app/Contents/Resources/Transmit.icns -actions "Show Local","Show Remote","Show Both" -dropdownLabel "Show…?"

…yields…

Choosing any of the 3 options (if "save results to variable" is selected) returns the literal string, so, Show Local, Show Remote, or Show Both, which you can then test against and branch your macro.

In this very simple example:

Show Local opens my local backup folder.
Show Remote opens the web url of my host's backups.
Show Both… shows both.

alerter -message "Opening the Backup Manager now…" -title "Clear out old backups" -subtitle "It's safe to remove all but the latest." -appIcon /Applications/Transmit.app/Contents/Resources/Transmit.icns -reply "Placeholder Text Here"

…yields…


The returned text can then be processed and acted upon. :clap:

I'm thinking of TONS of uses for this. I imagine you will too.

I hope this helps someone and I would love to hear your thoughts.

4 Likes

Thanks very much for alerting me to that! I downloaded version 3 and it doesn't run for me (Mohave) and I notice that on GitHub issues have been raised about that version. Version 2, however, works fine for me and I look forward to thinking of lots of ways to put it to use.