Reputation: 1005
I am having trouble getting a bash script running through a plist that will be launched through launchctl
.
When I run it normally through bash by running sh script.sh
everything works fine and it runs as it should and no complaints about jq
.
However when I try launching that same script through a plist launch agent with launchctl
, it still starts fine, but it exits with an error code 127
, from which I can see in my error logs that it throws:
line 9: jq: command not found
jq
is installed through brew
and I also installed the binary manually in usr/local/bin
, but that also does not seem to work. I have no idea whats going on. I will put some of the relevant code snippets here:
The code lines where it fails in spotify-slack.sh
JSON=$(echo '{}' | jq --arg SONG "$SONG" --arg ARTIST "$ARTIST" --arg EMOJI "$EMOJI" '.profile.status_text=$ARTIST+" - "+$SONG | .profile.status_emoji=$EMOJI')
curl -X POST --data "$JSON" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json; charset=utf-8" --silent -o /dev/null https://slack.com/api/users.profile.set | jq 'del(.profile)'
The plist file
<?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>Label</key>
<string>com.user.spotify-slack</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>/Users/brulmanj/src/spotify-slack/spotify-slack.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardErrorPath</key>
<string>/Users/brulmanj/src/spotify-slack/.logs/error.log</string>
<key>StandardOutPath</key>
<string>/Users/brulmanj/src/spotify-slack/.logs/output.log</string>
</dict>
</plist>
Thanks in advance!
Upvotes: 1
Views: 19