The Code Train

Where Neil Crosby talks about coding on the train…

RSS Entries

How to Automatically Take Photos Using Your Mac’s Webcam

Posted on November 2nd, 2008 by Neil Crosby. Filed under Blog Posts.

On friday, Norm happened across one of my automated photos on Flickr and asked me how I did it. Because I realised that I couldn’t actually remember exactly how everything fitted together I decided to take a look at it again this weekend and actually write things up this time.

Where is my happy face, take 2

So, here’s how to do it:

  1. Create a directory /Applications/autocamcapture – this is where the executables we’ll be using will live.

  2. Create a directory ~/Pictures/autocamcapture – this is where the automatically generated images will live.

  3. Download CamCapture and put the executable in /Applications/autocamcapture

  4. Open the “Script Editor” application and enter the following:

    set commandPath to "/Applications/autocamcapture/"
    set commandName to "camcapture"
    set outputImagePath to "~/Pictures/autocamcapture/"
    set outputImageName to do shell script "date +%Y%m%d-%H%M%S"
    do shell script commandPath & commandName & " " & outputImagePath & outputImageName
  5. Save this file as /Applications/autocamcapture/autocamcapture.scpt

  6. Open a terminal window, and run crontab -e. Add the following cron job:

    *      *       *       *       *       osascript /Applications/autocamcapture/autocamcapture.scpt
  7. Now, once a minute a cron job will be fired off and a picture will be taken and placed in your ~/Pictures/autocamcapture directory.

The obvious question to go with this is “but why would you do this?”. Frankly, originally the answer was just “because I can”. I carried on doing it though because in amongst all the dross that inevitably gets taken some interesting photos do occur. Try it out yourself, you might snap something fun.

Tags: , , , , ,

If you enjoyed this post, subscribe to The Code Train and read more when I write more.

9 Responses to “How to Automatically Take Photos Using Your Mac’s Webcam”

  1. I tried this out (though I made it fire only once every 15 minutes) and found I kept getting mails from cron. It seems osascript outputs a blank line when run so cron dutifully mails it to you when the command executes. Since I couldn’t work out how to suppress it, I went the slightly dubious route of redirecting the output to /dev/null.

    osascript /Applications/autocamcapture/autocamcapture.scpt > /dev/null 2>&1

    It’s a bit sledge-hammerish, and if the command ever has legitimate reason to give output, you won’t find out. However, it stops your system mailbox filling up with crud.

  2. Yup, doing the “redirect everything to /dev/null” thing does work, but as you say you won’t get legitimate output being sent to you.

    Unfortunately, sometimes there is legitimate output, as I found out a couple of days ago – for some reason the camera wasn’t able to be initialised, and the info about this was being sent to stderr which was then being consumed into /dev/null. I’ll keep poking to see if I can come up with a better solution.

  3. It seems the blank line is actually sent to stdout, so if you just redirect to /dev/null and don’t redirect stdout to stderr then everything will be dandy, provided the programs involved all correctly use stderr when there’s a problem.

  4. i use picanom ( :o) its a simple online tool and lets me save jpegs – all it needs is a webbrowser to load in and a webcam installed – crossplatform so works on pc/mac/lin and wht not

  5. Hey Nick, picanom looks like a cool tool and great if you want to take a one-off pic with your webcam but don’t know how to use the software that came with it. The idea behind autocamcapture though is that it will carry on taking pictures once a minute all the time, with no intervention from you – the two tools have pretty different use cases.

  6. There is an up-to-date version of autocamcapture.scpt on Neil’s github repository, which uses a different naming convention for the output images and fixes a problem with using the webcam when your system is waking up:

  7. Hey Can I use it in order to take only one picture on startup?

  8. The site with the camcapture binary is not available anymore, but the wayback machine ( has it:

  9. I understand of ovens that are around 100 years-old, passed from generation to era. He sniffed the air and listened exceedingly, hardly recognizing everyone even though I was completely view.

Comments RSS

Leave a Reply

TheCodeTrain Theme by Neil Crosby, Powered by WordPress