elektroholunder

The official site of the Ministry of Fairness, Niceness, and Free Ponies

How to take timed screenshots in OSX

I’m working on a video for marketing purposes and needed a solution that takes screen captures of my desktop every minute or so.

At first I played around with /usr/sbin/screencapture and crontab, but that only produced black images, since cron doesn’t run it as the right user. This is what worked for me:

  • create the following Applescript (source) and save it somewhere as an app:
set DATE_TIME to do shell script "date +%Y_%m_%d_%H%M"
set fname to DATE_TIME & ".png"
do shell script "/usr/sbin/screencapture -x <save path>" & fname
  • add this line to your crontab file to take a screenshot every minute, all the time:
* * * * * open -g <path to your Applescript app>

The -g parameter to open causes the Applescript to be executed in the background instead of stealing focus away from your front-most app every sixty seconds.