You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Trying to figure out why a launchd user agent won't run a bash script.

I'm trying to write a bash script that creates a couple of other shell scripts and loads them into launchd as user agents.


I'm stuck. Here's the current script: https://github.com/sethgoldin/davinci-resolve-postgresql-workflow-tools/blob/mac os-unified-tools/davinci-resolve-postgresql-workflow-tools-optimize-agent-macos/ macOS/automate-workflow.sh


Running the shell scripts inside

/backup
and
/optimize
manually works fine, but launchd just doesn't run them for some reason. Furthermore,
launchctl list
is showing the
backup
agent with an exit code of 0, but the
optimize
agent with an exit code of 127.


My hunch is that something is amiss down in the heredocs that create the launchd user agents, on lines 65-82 and 84-101.


Can any launchd gurus help me out?


I'm on macOS 10.12.6.

Posted on Mar 21, 2018 2:20 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 21, 2018 3:43 PM

Figured it out. The heredoc for the

launchd
was using
$HOME
which expands to
/Users/username
. It turns out that
launchd
actually gets tripped up with that very first
/
. That seems like insane design, but I'm not a programmer. The fix is to use
Users/$USER
instead.


I hope this helps someone who stumbles across this at some point!

Similar questions

4 replies
Question marked as Top-ranking reply

Mar 21, 2018 3:43 PM in response to Seth Goldin

Figured it out. The heredoc for the

launchd
was using
$HOME
which expands to
/Users/username
. It turns out that
launchd
actually gets tripped up with that very first
/
. That seems like insane design, but I'm not a programmer. The fix is to use
Users/$USER
instead.


I hope this helps someone who stumbles across this at some point!

Mar 22, 2018 8:40 AM in response to Seth Goldin

Hello Seth,

I suggest you try again with $HOME. Using "Users/$USER" is not correct. There is no guarantee that "Users/$USER" is a user's home directory. I'm not sure what was going on with the $HOME version, but I can assure you there is no problem with an absolute path. It sounds like you should be using the "Program" key instead of "ProgramArguments" since your executable doesn't have any arguments.

Trying to figure out why a launchd user agent won't run a bash script.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.