I have a long series of commands that I run on a semi-regular basis. Sometimes, completion of the commands requires user input via password prompt or other responses and sometimes information is output in the course of these commands that I need to copy to a log elsewhere. Mostly, though, the script can run unattended as it processes its lengthy series of tasks.

I've come across dozens of scripts and tools that will tell you when your command has finished running. But that's not what I need. And I've come across tools that should be able to convert varied output into a notification, but there's no accompanying documentation explaining how to do this.

So, if I wanted to be sent a banner notification through Notification Center every time the phrase "space cats" was output during the running of my command, how would I trigger that notification to be sent?


If I understand you correctly, you can access the output of your scripts. Then you can do something like this:


# Replace the echo with your script
echo "space cats" | grep "space cats"

if [[ "$?" -eq "0" ]]; then
    osascript -e 'display notification "Attention!" with title "Notification" subtitle "I found space cats" sound name "Submarine"'
  • 1
    Love it (+1). An alternative to osascript may be the Run Shell Script action from the Automator application. It seems that osascript is summoned by a shell script, whereas Run Shell Script action summons a shell script. Based on the paucity of resources Apple has devoted to osascript, it seems their strong preference is for developers to use an "Apple-centric" (and therefore less open) approach to shell programming. A bit hypocritical of them perhaps, given that they tout their Unix roots when it suits their narrative. – Seamus Mar 27 at 15:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .