Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to run a script every minute (or 20 seconds) between 06:30 and 10:30 every weekday using launchd. I have the script running every minute / X seconds now, but I don't know how to limit this to workdays between two defined times.

The question Run a cron job every 5 minutes between two times give the answer for cron, but I'd like to do the same using launchd.

How do I do this?

share|improve this question

StartCalendarInterval can also be an array of dictionaries like this: for w in {1..5}; do for h in {6..11}; do echo "<dict><key>Weekday</key><integer>$w</integer><key>Hour</key><integer>$h</integer><key>Second</key><integer>0</integer></dict>"; done; done | pbcopy.

You could also run the script every minute but exit it depending on the time or date:

weekday=$(date +%u)
hour=$(date +%-H)
min=$(date +%-M)    
[ $weekday -ge 6 ] && exit
[ $hour -le 5 -o $hour -eq 6 -a $min -le 29 ] && exit
[ $hour -ge 11 -o $hour -eq 10 -a $min -ge 31 ] && exit
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .