Any way to trigger a flow based on MacOS Notification?

Hello Guys,

Im looking for a way to trigger a Node-Red flow when a specific notification is triggered on a remote Apple Mac via the native MacOS notification platform.

I can't figure out how best to do this, this Mac is being used as a headless server so isn't monitored actively, I'm hoping to trigger a flow that will issue a push notification via my Home Assistant instance when such an event is triggered.

Any ideas?

Screenshot 2023-02-16 at 20.11.06

The notification is produced based on some result, looks like creation of an mkv. Can you not monitor the output directory of that mkv instead ? There is a "watch" node, that can monitor directories/files. I don't think you can capture that notification, unless it is being logged somewhere in a log file.

Hmm, not looking good. I did a search which turned up nothing positive, then I tried the new Bing search GPT AI function:


Ah, but ChatGPT seems to be more hopeful. so maybe try this out:

To trigger a webhook when a notification is shown on a Mac, you can use a combination of native Mac tools and a third-party app. Here's a general outline of the steps involved:

  1. Install the "terminal-notifier" package using Homebrew. To install Homebrew, open a Terminal window and run the following command:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Then run the following command to install terminal-notifier:brew install terminal-notifier
  2. Write a script that will listen for incoming notifications and trigger a webhook when a notification is shown. Here's an example script that uses the "jq" command-line tool to extract the notification title and message, and then uses the "curl" command to send a webhook:
#!/bin/bash

# Listen for incoming notifications
terminal-notifier -group mygroup -title '' -message '' -sender com.apple.Terminal -json |

# Extract the notification title and message
jq -r '.["title"] + "\n" + .["message"]' |

# Send a webhook using curl
xargs -I{} curl -X POST -H "Content-Type: application/json" -d '{"title": "Notification Triggered", "message": "{}"}' https://your-webhook-url.com
  1. Save the script as a file, for example "trigger-webhook.sh".
  2. Make the script executable by running the following command in the Terminal:chmod +x trigger-webhook.sh
  3. Set up a "Launch Agent" to run the script in the background whenever the system is running. Here's an example Launch Agent file that you can modify to your needs:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.yourdomain.trigger-webhook</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/trigger-webhook.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
  1. Save the Launch Agent file as "com.yourdomain.trigger-webhook.plist" in the directory "~/Library/LaunchAgents/".
  2. Load the Launch Agent by running the following command in the Terminal:launchctl load ~/Library/LaunchAgents/com.yourdomain.trigger-webhook.plist

That's it! Your Mac will now listen for incoming notifications and trigger a webhook whenever a notification is shown. You can modify the script to extract different parts of the notification, or to trigger different webhooks based on the notification content.

I don't see how this would work. OP wants to trigger a flow based on the notification he receives, not to create one:

terminal-notifier: Send User Notifications on macOS from the command-line.

But it is marked as solved, I am intrigued.

In Node-RED, you create a web endpoint (a webhook) that is the trigger for a flow.

On the mac you use the 3rd-party tool for watch for the notification and trigger a web GET to that endpoint.

That's it. Job done. (Assuming it works, I didn't test it because I really can't be bothered to dig out my Macbook Pro, wait for all its updates, install node.js and node-red and the 3rd-party app, work out how to create a repeatable notification, write the apple script and node-red flow!! :rofl:

But hey, done once, it should work forever.

On the mac you use the 3rd-party tool for watch for the notification and trigger a web GET to that endpoint.
That's it. Job done.

Sure, except that is not what it is doing.
"watch" for the notification - needs to be extracted/triggered from somewhere, log, database etc (if it is even logged), but it is not the terminal.

incoming notifications and trigger a webhook when a notification is shown

# Listen for incoming notifications

Isn't it doing what it says it is doing?

Sure, for stuff created/triggered in the terminal…