Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've created a script to update my package manager and post a notification via terminal-notifier. When run manually, it works fine, but when called via launchd (local to the user, in ~/Library/LaunchAgents/), terminal-notifier seemingly doesn't start. It doesn't hang, however; later parts of the script run as expected. Nothing is produced on stdout/stderr. I'm using absolute paths in everything, so that's not the problem either in terms of manual vs. launchd execution. I'm fairly sure this is just another stupid quirk of launchd, but is there any way to overcome it?

Launchd agent

<?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.brew.autobrew</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/[USERNAME]/.scripts/autobrew.sh</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Minute</key><integer>0</integer>
        <key>Hour</key><integer>22</integer>
    </dict>
    <key>AbandonProcessGroup</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/tmp/autobrew_launchd.log</string>
    <key>StandardErrorPath</key>
    <string>/dev/autobrew_launchd.log</string>
</dict>
</plist>

The relevant line of code in autobrew.sh

/usr/local/bin/terminal-notifier -title "Homebrew updates" -sound default
share|improve this question

1 Answer 1

I was having this same problem and couldn't figure it out either. I finally remembered reading in terminal-notifier's README.markdown that:

In order to use terminal-notifier, you have to call the binary inside the application bundle.

So I edited my script to call /Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier instead of /usr/local/bin/terminal-notifier and that took care of the problem. While the /usr/local/bin/ executable works fine when the script is called from the interactive shell, for some reason launchd needs to use the version encapsulated inside /Applications/terminal-notifier.app to work properly.

(Note that if you install terminal-notifier with Homebrew, you'll have to make sure to run brew linkapps to create the necessary symlink in your Applications folder, per brew info terminal-notifier.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.