Murphy Mac » Page 'Schedule a Command without Cron'

Schedule a Command without Cron

Share

cron alternateIf you only have a few minutes to schedule a job you might not feel like digging into cron for your kickoff tool - especially if you’ve never used it before. In fact, Apple is kind of discouraging the use of cron in favor of launchd these days.

If you came from Windows you might be happy to see OS X has the AT command you might be oh-so-familiar with. Until you realize Apple doesn’t really want you using that either. That’s a shame, because AT is quick and dirty and supports some simple syntax, like now + 3 hours, to set a time for kickoff. In fact, you can specify teatime as a time, which really means 4pm.

If you’re sleepy and want to schedule a job and you don’t want to mess around, iCal might be the answer. You can use the alarm feature of an appointment to run an Applescript. Just set the time and pick your script like you see in the picture.

cron alternative

Your script can be pretty simple. Something like the screenshot below should work. Just replace the text following “do script” in the double quotes with whatever your terminal needs require.

cron alternative

The articles linked above mention the downsides of cron and AT - mostly dealing with sleeping machines and hard drives that can’t rest because AT is frequently checking to see if it has anything to do. That’s why OS X doesn’t enable AT by default. If your machine will be sleeping when you need the command to run you can wake it up with the Energy Save in System Preferences.

No screencast for this one. If you want to shed any light on how you schedule your routine jobs let us know in the comments. As always, be careful with the Terminal. You can break something very easily!

Share/Save/Bookmark

More on Applescript | Permalink

2 comments to “Schedule a Command without Cron”

  1. If you just want to run something a short-while later, the sleep terminal command is useful.

    For example, if you want to run the say “Hello” command in 10 minutes:
    sleep 600 && say “Hello”

    It’s best to use && instead of “sleep 600; say …” - with ; , if you abort the sleep command (ctrl+c) the next command will run anyway..
    Not really a problem in this case, but if you do “sleep 100; halt” and you try to cancel it, it’ll shutdown immediately..
    The && basically means “if the previous command run without errors, do the next”

    The biggest annoyance with the sleep command is you have to enter the times in seconds.. But it’s easy to work out how many seconds there are in the required time..
    - Ben

  2. Thanks Ben - great tip. I’ve been using it all week!

Leave a comment