Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative Path in launchd plist

I am currently using a plist to run a shell script.

 <?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.name.set</string>
                <key>Program</key>
                <string>/Users/username_here/Desktop/simple.sh</string>
                <key>RunAtLoad</key>
                <true/>
                <key>StartInterval</key>
                <integer>5</integer>
                <key>StandardErrorPath</key>
                <string>/tmp/com.name.example.stderr</string>
                <key>StandardOutPath</key>
                <string>/tmp/com.name.example.stdout</string>
        </dict>
        </plist>

This works! But when I change the program name to be

<string>/Desktop/simple.sh</string>

it doesn't run the script. also ~/Desktop/simple.sh does not work.

Is there a way to run the script without knowing the username and using an absolute path?

I am also getting this error message when I tail launchd.

com.apple.xpc.launchd[1] (com.name.example[8178]): Service could not initialize: 14F27: xpcproxy + 13421 [1402][AD0301C4-D364-31CE-8BA7-B5DBECE64D0A]: 0x2

Thanks!

like image 739
Peter Kaplan Avatar asked Feb 02 '17 20:02

Peter Kaplan


People also ask

How does the launch plist script work?

As mentioned in that Mac launchd tutorial tutorial, this launch plist script does the following things: Runs a Unix shell script named /Users/al/bin/crontab-test.sh. Runs that script every minute, as given by the StartInterval tag.

How to name a plist file for a job?

Thus, if your job label is "com.apple.sshd", your plist file should be named "com.apple.sshd.plist". Label <string> This required key uniquely identifies the job to launchd .

Is there a launchd plist file for Spotlight?

Just looking at a few Mac launchd examples here, the MacOS launchd plist file for Spotlight is surprisingly simple: The only thing they're really doing there is using the KeepAlive tag.

What's the difference between launchd and SSH plist files?

Just looking at a few Mac launchd examples here, the MacOS launchd plist file for Spotlight is surprisingly simple: The only thing they're really doing there is using the KeepAlive tag. On the other hand, their ssh.plist file is much longer, and demonstrates several other pieces of the Mac plist vocabulary:


1 Answers

Using a shell as arg0 and giving it a path relative to the user's home folder works for me:

<key>ProgramArguments</key>
<array>
    <string>zsh</string>
    <string>-c</string>
    <string>~/CLI/scripts/list_open_jira_tickets --skip=5297 &gt; ~/CLI/tmp/open_jira_tickets.txt</string>
</array>
like image 95
Orangenhain Avatar answered Sep 24 '22 04:09

Orangenhain