Lingon for scheduled tasks
October 21, 2008 at 3:11 PM by Dr. Drang
In yesterday’s post, I mentioned that the script described there would be a good candidate for scheduling to run every day in the early morning hours. My years as a Linux user lead me to think of cron
whenever I want to schedule a program to run repeatedly, but cron
—although available—is déclassé on the Macintosh, where launchd
is preferred.
To add a new scheduled task with cron
, you simply add one line to a file. The whitespace-separated fields of the line describe the command to run and the days, hours, minutes, etc. that it should run. It’s usually quite simple, although complicated schedules can make the format of the line pretty hairy.
With launchd
, you have to create a plist configuration file, which isn’t nearly as easy as adding a single line to a cron
file. Here’s the configuration file for running my twitterpost
program every day at 1:00 am:
<?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.leancrew.twitterpost</string>
<key>ProgramArguments</key>
<array>
<string>/Users/drang/bin/twitterpost</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>1</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Nasty, eh? Fortunately, Lingon, a free utility written by Peter Borg, takes the pain out of creating launchd
configuration files, making it even easier than cron
. Here’s the Lingon screen that generated the configuration file above:
Ahh, much better.
Peter Borg is also the programmer behind Smultron, the free Mac text editor.