Unable to load script via launchctl “command not found”

launchctllaunchd

I have a problem loading a script to watch a folder via fswatch in /Library/LaunchAgents
The script runs fine when run from terminal, but via my plist, it gives me "Command not found" for fswatch in the log.
I bet it has to do with where the script is placed / paths specified or not but I can't figure it out. Here it is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Debug</key>
    <true/>  
    <key>Label</key>
    <string>org.papers.fswatch</string>
    <key>OnDemand</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/bin/papersfswatch.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>    
    <key>StandardErrorPath</key>
    <string>/Users/x/Documents/Computer/Logs/papersfswatch.log</string>
    <key>StandardOutPath</key>
    <string>/Users/x/Documents/Computer/Logs/papersfswatch.log</string>
</dict>
</plist>

When I load it with sudo launchctl load /Library/LaunchAgents/org.papers.fswatch.plist it gives me a Service only ran fo 0 seconds warning
and in the log I get

    /usr/local/bin/papersfswatch.sh: line 2: fswatch: command not found 

Line 2 is, of course, the fswatch command. Why does it not find it, if it's found from Terminal, and how do I point it to it.
Any help much appreciated!

J

Best Answer

Problem solved.

It seems the script needs the absolute path to fswatch (for whatever reason) when run via a plist. In this case /usr/local/bin/fswatch Running from Terminal fswatch will do fine, but not in this case.

Related Question