I have a bash script called
foo.sh that takes one command line argument,
bar. I want it to run every
60 seconds and load at startup.
- an XML
plistis Apple Property List
com.mydomain.foo.plistName of launchd plist file should be a reverse fqdn, like (this may not be required, but convention)
$HOME/Library/LaunchAgentsand is ran as that user.
com.mydomain.foo.plistcan also live
/Library/LaunchAgents, have requirements, ran as
launchctl load com.mydomain.foo.plist
lauchctl unload com.mydomain.foo.plist
/var/log/system.logif you are having issues with
"If the system is turned off or asleep, cron jobs do not execute; they will not run until the next designated time occurs. If you schedule a launchd job by setting the StartCalendarInterval key and the computer is asleep when the job should have run, your job will run when the computer wakes up. However, if the machine is off when the job should have run, the job does not execute until the next designated time occurs."
<?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.mydomain.foo</string> <key>ProgramArguments</key> <array> <string>/path/to/foo.sh</string> <string>bar</string> </array> <key>Nice</key> <integer>1</integer> <key>StartInterval</key> <integer>60</integer> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/path/to/foo.err</string> <key>StandardOutPath</key> <string>/path/to/foo.out</string> </dict> </plist>