The key to effective launchd jobs is specifying the circumstances under which they will run. The most frequently used options are found on the Basic, Miscellaneous, and Paths panes in Lingon.
RunAtLoad: Select this option to make your launchd item run immediately when the job loads. Any job you wish to run at startup or login should have RunAtLoad selected.
OnDemand: If you select this option your launchd item will quit after each use. If you don’t select this option, your item runs continuously; if it quits or crashes, launchd relaunches it immediately. That’s a good thing if you need to keep important items (for example, server programs or network monitoring utilities) running all the time.
StartInterval: To set your item to run at a fixed, repeating interval (such as every 10 seconds), enter the number of seconds in the StartInterval field on the Miscellaneous pane. For example, to run a backup command (such as rsync) every 4 hours, enter
StartCalendarInterval: These fields work similarly to the calendar intervals for
cron: enter a number for specific weekday, month, day, hour, or minute intervals, or leave a field blank to indicate “all.” For instance, if you want a reboot script to run every day at 2:30 a.m., enter
2in the Hour field,
30in the Min field, and leave the rest blank. Launchd’s calendar intervals did not function correctly in Mac OS X 10.4 or 10.4.1; these problems were corrected in the 10.4.2 update. Even so, unlike cron, launchd cannot currently use ranges of numbers; each field must contain a single integer or be empty.
StartIntervals always override StartCalendarIntervals. If you’ve entered a StartInterval of, say, every 60 seconds, your item will always run every 60 seconds, even if you specified in StartCalendarIntervals that it should run only during certain times or on certain days.
QueueDirectories: If you enter the path to a normally empty folder in this section of the Paths pane, your launchd item runs whenever an item appears in that folder and then quits if the folder becomes empty. This condition is ideal for scripts that process, and then immediately delete, files that appear in a certain folder.
WatchPaths: Watch paths function somewhat like AppleScript Folder Actions, except that they can trigger any program or script—not just AppleScripts—and can watch files as well as folders. Enter a path here, and your launchd item runs whenever that item changes in any way. If you enter the path to a folder, the item runs whenever a file is added to, removed from, or modified within that folder (changes to the contents of subfolders are ignored).
Troubleshoot your job
Code is picky, picky, picky! A stray space, incorrect capitalization, or typo can sink your job. If a launchd job doesn’t work correctly, click Unload to turn it off. Double-check your script (if any) by running it manually in Terminal. Then compare your job’s .plist contents in Lingon’s Expert pane against the screen shots you see here. If everything matches, go to the Basic pane, ensure that the Disabled option is not selected and click on Just Save. Then click on Reload to reload the job.
The Backup Job: When you click on the Expert tab in Lingon, the code for your backup job should look roughly like this. (You’ll, of course, be backing your Users folder up to your own destination, so that name will be different.)
The DropBox Job: When you click on the Expert tab in Lingon, the code for your dropbox job should look roughly like this. (Your user name will show here instead of mine.)