Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.