Using Launchd on Mac OS X

Mac OS X has never used cron for timed execution of scripts. Starting with Mac OS 10.4, all processes are started with launchd, which not only runs startup scripts, but also runs cron jobs. Before 10.4 StartupItems were used.

The following configuration runs the script /usr/local/myscript.sh both at startup, as well as every 2 minutes (120 seconds).

 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  Label com.example.myscript Program /usr/local/myscript.sh        RunAtLoad StartInterval 120

Depending on the usage, you should place this file either in /Library/LaunchDaemons or /Library/LaunchAgents.


 * /Library/LaunchDaemons: If your job needs to run even when no users are logged in.
 * /Library/LaunchAgents: If it is only useful when users are logged in.

Before you install the file, decide on it's identifier. The above script is identified by com.example.myscript, as shown in the Label field. Save this file as /Library/LaunchAgents/com.example.myscript.plist (using the key you have chosen).

This file will be automatically loaded and acted upon after reboot. In addition, you can manipulate it using the launchctl</tt> tool. To load and run this script without rebooting, do the following:

sudo launchctl load /Library/LaunchAgents/com.example.myscript.plist sudo launchctl start com.example.myscript

You can verify it's status using

launchctl list