To schedule script in OSX to run every now and then you can use launchd. Add a scheduled job by saving a .plist in folder **/Users/
1. Example .plist
This example is saved as se.christianengvall.dostuff.plist in the folder mentioned above.
<?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>se.christianengvall.dostuff</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/php</string>
<string>/Users/<my-user>/Sites/dostuff.php</string>
</array>
<key>StartInterval</key>
<integer>10</integer>
</dict>
</plist>
Set the label value to the same name as the file. In ProgramArguments we set the path to php and the path to the script we want to run. The StartInterval sets how often to run the script, set in seconds.
2. The php script
<?php
syslog(LOG_WARNING, "printing value to log");
Nothing much going on here, just add a message to the system log.
3. Schedule script in OSX
Now to schedule the script run this in a terminal:
launchctl load /Users/<my-user>/Library/LaunchAgents/se.christianengvall.dostuff.plist
Now start the Console utility and watch your script print: “printing value to log” every ten seconds.
4. Stopping the script
launchctl unload /Users/<my-user>/Library/LaunchAgents/se.christianengvall.dostuff.plist