Launch time

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

14400
seconds.

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
2
in the Hour field,
30
in 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).

1 2 3 Page 1
Page 1 of 3
Shop Tech Products at Amazon