Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I want to set cron to capture the current desktop every hour:

screencapture -Cd -tjpg ~/Desktop/screen-`date +"%Y%m%d-%H%M"`.jpg

I tired this method but it seems doesn't work on Mountain Lion. I also tried Lingo but with no luck. Any ideas?

share|improve this question

1 Answer 1

cron behaves a bit differently than a standard prompt, which is why it's not doing what you're expecting. There are two issues with the command as is:

  • Because it doesn't parse the PATH environment variable the same was as the shell, cron doesn't know where screencapture is. You need to specify the full path, /usr/sbin/screencapture.
  • As noted in the crontab(5) man page, cron treats % as a newline character:

    Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

    So you need to escape each % with a \ to get your desired result.

This crontab entry will give you a screen capture every hour, on the hour:

0 * * * * /usr/sbin/screencapture -Cd -tjpg ~/Desktop/screen-`date +"\%Y\%m\%d-\%H\%M"`.jpg

Cron Error Logging

As an aside, if you're having issues with cron, check your system mail by running the mail command in Terminal. It's not very obvious, but by default cron sends error messages there that can provide a starting point to figuring out what's going wrong.

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.