MacOS LaunchDaemon - Zshell script won't expand ~ tilde

139 views Asked by At

So if I place my plist file into my /Library/LaunchDaemons folder my zshell script won't expand the ~ to the current user logged in. I have to specify the full path on my shell script to the user where I want a file to be placed. ie Users/myusername/filepath/mylog.log

However, if I put the same plist file into the /Library/LaunchAgents folder and refer to the same file, the ~ in the .zsh script expands just fine. I'm confused by this behavior? (I can just put ~/filepath/mylog.log and it expands no problems

(The zshell script I'm launching is my /usr/local/bin folder.) I use the ~ extensively in my scripts so I'm trying to figure out how to get my zshell script to expand the ~ when I have a plist executing the file from the LaunchDaemon. (I need the script to launch in sleep mode or when the user is logged out.)

1

There are 1 answers

0
nwood21 On

So unlike Agents, Daemon's require that you put the user and group that you want to run the daemon under. Since ~ is an environmental variable equivalent to $HOME (same thing) the .plist / Daemon doesn't understand where $HOME is if you haven't specified which user account. Make sense. Do that this way:

<key>GroupName</key>
<string>yourgroup</key>
<key>UserName</key>
<string>myusername</string> 

Please note - Launch Control app can be very helpful for this.