C-Command Software Forum

Bash script issue for terminal commands

I’m having trouble getting bash scripts to run for notifications, either by calling terminal-notifier (which is installed and working) or by other shell scripts. I’m running ToothFairy 2.6 on Mojave 10.14.6. I see the gear meaning the script is running, but no notifications show up and there’s nothing in Console.

This works:

#!/bin/sh
osascript -e 'display notification "Connected" with title "AirPods"'

but this does not:

#!/bin/sh
terminal-notifier -message "Connected AirPods" -title "ToothFairy"

It’s good that the osascript script for posting to Notification Center is working. Besides the terminal-notifier one, which other scripts are not working? Does that command for Terminal Notifier work if you run it directly from Terminal?

If the system reports an error when running the script, ToothFairy will log it to Console. The easiest way to find it is by entering a search for MJTLogger before the script will run.

You can also enter this Terminal command:

defaults write com.robinlu.mac.Tooth-Fairy LogScript YES

to enable logging for when the script starts and finishes running.

terminal-notifier works if I call it directly from Terminal.

After turning on logging, here’s the error:

Error running script: Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={
    NSURL=file:///Users/[username]/Library/Application%20Scripts/com.robinlu.mac.Tooth-Fairy/1.connected, 
    NSLocalizedFailureReason=/Users/[username]/Library/Application Scripts/com.robinlu.mac.Tooth-Fairy/1.connected: line 2: terminal-notifier: command not found}

actually, adding in the full path to terminal-notifier works:

#!/bin/sh
/usr/local/bin/terminal-notifier -message "Connected AirPods" -title "ToothFairy"

Glad you figured it out. That error should be visible even without turning on the debug logging. I guess somehow your $PATH was not correct in the environment that was running the script.