Uncategorized

This was a problem that took more time than I wanted to solve. Hopefully posting this will help somebody find the answer faster than I could.

The launchd.plist documentation is pretty clear that StartCalendarInterval is way to approximate a crontab-like entry. The documentation is a little light on examples.

I wanted to do something like…

0,30 */4 * * * /bin/blah

All of the examples show single values for each of the five possible time arguments. The good news is that it’s possible to nominate more than one time. The bad news is that you can’t combine them into the same concise shorthand that cron used. Instead you define an array of dictionaries…

<key>StartCalendarInterval</key>
<array>
  <dict>
    <key>Hour</key>
    <integer>0</integer>
    <key>Minute</key>
    <integer>0</integer>
  </dict>
  <dict>
    <key>Hour</key>
    <integer>4</integer>
    <key>Minute</key>
    <integer>0</integer>
  </dict>

After I got this answer from the Apple development forum, I also found this on Stack Overflow: http://stackoverflow.com/questions/2079130/run-a-cron-job-every-x-minutes-with-startcalendarinterval-launchd