# Any way to trigger a flow based on MacOS Notification?

**URL:** <https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312>\
**Category:** General\
**Created:** [16 February 2023 20:27 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312 "2023-02-16T20:27:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aperture1988](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aperture1988/32/40681_2.png) [@aperture1988](https://discourse.nodered.org/u/aperture1988)\
**Post date:** [16 February 2023 20:27 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/1 "2023-02-16T20:27:36Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e113cda34332217a0dfdedd4e9640675c54935f.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 February 2023 21:02 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/2 "2023-02-16T21:02:45Z")

</div>

> [@aperture1988](#):
>
> specific notification is triggered

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.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 February 2023 22:18 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/3 "2023-02-16T22:18:59Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f3b60ad3aa02861db1898d5683da5273a03bf3f2.png)

* * *

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:

```auto
#!/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:

```auto
<?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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 February 2023 23:07 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/4 "2023-02-16T23:07:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 February 2023 00:40 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/5 "2023-02-17T00:40:58Z")

</div>

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!! 🤣

But hey, done once, it should work forever.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [17 February 2023 06:44 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/6 "2023-02-17T06:44:08Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 February 2023 11:54 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/7 "2023-02-17T11:54:45Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [17 February 2023 12:07 UTC](https://discourse.nodered.org/t/any-way-to-trigger-a-flow-based-on-macos-notification/75312/8 "2023-02-17T12:07:27Z")

</div>

Sure, for stuff created/triggered in the terminal…
