I have the following plist file at ~/Library/LaunchAgents:
<?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.yogapo.test_launchd</string>
<key>Program</key>
<string>. /Users/luke/dev/data_yogapo/script/test_launchd.sh</string>
<key>StartInterval</key>
<integer>10</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
And the test_launchd.sh file is contains the following:
#! /bin/bash
echo "hello world from test_launchd.sh" >> /Users/luke/dev/data_yogapo/log/development.log
When I run test_launchd.sh manually with
. /Users/luke/dev/data_yogapo/script/test_launchd.sh
the results are as expected: the line appears at the end of development.log
But when I load up this plist file, nothing happens:
$ cd ~/Library/LaunchAgents
$ launchctl load com.yogapo.test_launchd.plist
$ launchctl list | grep yogapo
- 1 com.yogapo.test_launchd
I’ve tried this with and without the RunAtLoad key. I’ve looked at other answers here on SO as well as elsewhere on the internet. I’ve followed tutorials, and there’s simply nothing happening. Any help much appreciated – thanks!
You are asking
launchdto run progam calledIt will take the entire value of the
Programkey as the first argument toexecvp(see man execvp(3) for more details)If you were to examine the
systemlog, you would see something like:launchdis not a shell. However, it can interpret hash-bang character sequences to identify which program to use to interpret your script. Therefore, simply specify your script as the program to run:Note: Should you need to pass arguments to your script, use the
ProgramArgumentskey instead and put the whole command line there. For example: