Reputation: 1
I have a plist file that should start a shell script on startup.
<?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.app.localclient</string>
<key>Program</key>
<string>~/Documents/Local_client/Server.sh</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
I've saved the plist file as com.app.localclient.plist
and have tested the shell script which works fine. When I try to load the script with launchctl load com.app.localclient.plist
, it loads the plist but does not start the shell script. I've also changed the Program parameter ~
to /Users/username/
, but with no succes. Is there a way to make the plist start the shell script and can this be done without knowing the username of where the script is saved (so by using ~ in the path).
Upvotes: 0
Views: 1472
Reputation: 207465
Maybe try running a shell as that will know your $HOME:
<key>ProgramArguments</key>
<array>
<string>bash</string>
<string>-c</string>
<string>"$HOME/Documents/Local_client/Server.sh"</string>
</array>
In order to debug this, please try:
<key>ProgramArguments</key>
<array>
<string>bash</string>
<string>-c</string>
<string>"echo hi > /tmp/DEBUG.txt"</string>
</array>
and see if /tmp/DEBUG.txt
exists afterwards. If that works, try making the last string
"/usr/bin/whoami > /tmp/DEBUG.txt"
and then see what is in /tmp/DEBUG.txt
Upvotes: 2