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?


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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