Scheduling Jobs Using CronniX
February 21, 2008
Under OS X I wanted two things to happen at 5am every day. Firstly, I wanted iTunes to download my podcasts before I woke—during the off-peak download quota offered by my ISP. And secondly, I wanted EyeTV to delete the recordings it had made the day before, as those recordings would have already been exported to iTunes.
After setting the Mac to wake at 5am in System Preferences, I used CronniX to edit the crontab file (which is easier than "crontab -e").
2 5 * * * osascript -e 'tell application "EyeTV" to launch' -e 'delay 10' -e 'tell application "EyeTV" to delete recordings' -e 'end tell' > /dev/null 2>&1
3 5 * * * osascript -e 'tell application "iTunes" to launch' -e 'delay 10' -e 'tell application "iTunes" to updateAllPodcasts' -e 'end tell' > /dev/null 2>&1
iTunes actually doesn't need to be told to launch, after receiving the updateAllPodcasts command it launches and behaves as expected. Unfortunately EyeTV isn't as well behaved. I've included the same commands for iTunes as a matter of completeness. Note that "> /dev/null 2>&1" sends the output from cron to the big unix blackhole, else you'll receive e-mails everyday telling you if the jobs were completed successfully.
If your iPod is attached, you can have iTunes complete a sync by issuing the AppleScript command update.
For example:
tell application "iTunes" to update
If your goal is to allow the currently downloading podcasts to be copied to your iPod, you best allow some time for this to happen:
delay 600
tell application "iTunes" to update
That's 10 minutes. I'm lucky to have a decent amount of bandwidth. You may have to allow more time.