Feature Request: Can we get a button on notifications to trigger a macro?

This is just a feature request. I'm well aware that most feature requests are rejected for a wide variety of reasons. (E.g., impossible to implement; difficult to implement; not needed by most people; achievable by some other means; etc.) But I can still make requests!

Some (many) macOS apps allow you to click on a menu that appears in the lower right corner of its notification messages. For example, when a Reminder pops up from the Reminder app, I get an Options menu which lets me click on five options which sends a message to the app.

image

Is there any chance that KM could provide this feature? Yes, this would be a fairly complex feature to create, but it's certainly consistent with how macOS apps work.

In my case, I create a lot of macros that generate notifications, and it would be nice if these notifications gave the user a chance to ignore that type of notification for an hour, a day, a week, or permanently, not unlike the example in the screen shot above.

The way I imagine it working is as follows:

  1. There would also need to be a new action called "Notification With Options" that lets you pass a list of strings that the user would see as options to click on, as shown in the screen image above;
  2. When the user clicks on one of the items, the KM Engine will call a new instance of the same macro that triggered the notification;
  3. The %TriggerValue% that would be passed to the new macro is the text of the notification message;
  4. %TriggerBase% would be set to "Notification Choice Trigger", and
  5. There would need to be a new token called %TriggerNotificationOption% that tells the macro which option the user clicked on.

I think the main thing this idea has going for it is that this is how many macOS already work. But I'm not really sure how many people would want this feature. I use this feature all the time in macOS, such as getting a notification to immediately delete an incoming email, or to cancel a particular reminder. I think I recall The Architect recently saying he wanted to overhaul the notification system, and this is one possible direction that it could go.

Let the criticisms roll in.

2 Likes

Unfortunately, no, because Apple only allow end users to decide what format Notifications are supported, and only allow applications one option.

Unless they are Apple apps, of course, then they can do whatever they want.

There are a few apps that “hack” a solution to this by actually having multiple applications with different notification settings, but I don't have any plans to do that.

1 Like

I've not looked into this, but Actionable Notifications are on iOS, are they not available on macOS? If not, surely it's only a matter of time.

Many of the required bits are already there.

It would be nice (down the road) to have support for actionable notifications. Home Assistant uses them and they're very convenient.

EDIT(2): Just tested and this does work on macOS. Here's a link to the docs about how they work (to give you an idea about their implementation).

Noted. Thanks. So this falls under "impossible to implement" as I first mentioned.

I found this thread while investigating if it was possible to do the same. I found a solution, so I thought it was worth posting in case others are still looking and stumble across this thread, too.

I've done this using Alerter, integrating it into KM to trigger a configurable notification with buttons that trigger KM Macros.

You can install Alerter by downloading the latest zip:

Unpack the zip wherever you want and copy the path to the alerter unix executable file (Cmd+Option+C). If your path contains spaces, or if in doubt, drag and drop the file into the terminal to get a path that has correctly-escaped characters to use below.

In KM, create an 'Execute Shell Script' action, and paste the following code below to create an alert with a single button that you can configure to trigger a macro with a parameter:

#!/bin/bash

# Retrieve Keyboard Maestro variables
DISPLAY_TEXT="$KMVAR_LOCALNotificationTitle"
MESSAGE_CONTENT="$KMVAR_LOCALNotificationMessage"
PARAMETER="$KMVAR_LOCALTargetMacroParameter"

# Display alert with "Example Button Text" button
ANSWER=$(/PathToAlerter \
    -title "$DISPLAY_TEXT" \
    -message "$MESSAGE_CONTENT" \
    -actions "Display" \
    -timeout 6)

# Execute Keyboard Maestro macro if "Display" is clicked
if [[ "$ANSWER" == "Display" ]]; then
    osascript -e 'tell application "Keyboard Maestro Engine" to do script "XXXX-XXXX-XXXX" with parameter "'"$PARAMETER"'"'
fi

Tips:

  • Replace the variables at the top of the script with your own, or just hard-code the title and message.
  • Replace the XXXX with the macro's UUID or name
  • Replace "Display" with the text for the button's name
  • Replace the "/PathToAlerter" to the path you created earlier

LOCALNotificationTitle becomes KMVAR_LOCALNotificationTitle in the shell environment as a variable name. Ensure the shell action is configured to use these or all KM variables by clicking on the little dropdown arrow to the left of the action's script field.

I'm using this to display basic details of my client's information in the notification (I'm using obfuscated details here!), with a 'Display' button, which, when clicked, runs a KM macro, which I use to display more detailed information when triggered. The notification is a native MacOS banner notification, and acts exactly as you expect it to.

You can create an alert with a dropdown with additional options. Find more examples of how you can configure the script as per Alerter's documentation:

Interestingly, Alerter is open source, so I wonder if these features could be added natively to KM at some point (although I am sure that would be a ton of work).

Someone smarter than me could figure out a way to programmatically configure the shell script to take KM variables as inputs and dynamically configure a list of buttons and their actions. For now, I'm using different subroutine macros, each with a tweaked version of this shell script.

Since Alerter is open source, we can check if it is using a public or non-public API to achieve what it does. If the latter, it would go against Peter's requirements for inclusion.

That makes sense.

A quick search shows it uses a bunch of non-public API's, so that would be a no-go sadly. At least we can use it ourselves for these custom notifications.

I believe you. Over the years I've learned that if a feature isn't in KM, it's likely because the feature isn't available through a public API.