Someone sneaks into my cubicle while I’m at lunch and takes candy out of my desk. Petty, but stupid too. I want to set up something so that my webcam on my iMac takes photos every few seconds while I’m away from my desk so I can catch the culprit! How can I do that in a stealthy manner while the computer is otherwise asleep?
This is a great question! The first thing you’ll probably need to do is put a sticker over the tiny green light that illuminates when your webcam is activated. That’s the easy part.
For the rest of this, we’re going to delve into the command line, but before we do that, you’ll need to download a handy utility called ImageSnap, which can be found at an open source archive called SourceForge. I’ll save you the trouble of finding it, though. Just go to ImageSnap on SourceForge and click on the download link at the top.
What you’ll want to do is download the package to a separate directory on your Mac system. I have a directory called “bin” at the topmost level, so that’s where I save my version of ImageSnap.
Then launch Terminal.app (you can find it in the Applications –> Utilities folder) and move to the directory where you saved the compressed archive.
Lost with all of this? You’d be smart to grab a copy of my best-selling book Learning Unix for Mac OS X Mountain Lion to get started with the incredibly powerful Unix command line system hidden within Mac OS X.
Now type this (possibly slightly modified to match the version of ImageSnap you’ve downloaded):
$ gunzip ImageSnap-v0.2.5.tgz
$ tar xf ImageSnap-v0.2.5.tar
Everything happens lightening fast and when you’re done, there’s a new directory called “ImageSnap” in that folder. Move into it with “cd” and use the “ls” command to see what’s there:
$ ls -F ImageSnap.h ImageSnap.xcodeproj/ imagesnap* ImageSnap.m ReadMeOrDont.rtf
Great. Now you have the command you want, imagesnap. To use it, just type the program’s name:
Capturing image from device "FaceTime HD Camera (Built-in)"...snapshot.jpg
Takes about 5 seconds and, yes, the little green light will illuminate for a moment or two during the process (hence the need to cover it with a sticker, post-it or something similar.
The image captured? Here’s one of my typing in this particular blog entry:
That’s pretty cool. Now how to do a series of images over time? The easiest way is to let “imagesnap” do the heavy lifting, as becomes obvious with a quick invocation of the “-h” flag:
$ ./imagesnap -h USAGE: ./imagesnap [options] [filename] Version: 0.2.5 Captures an image from a video device and saves it in a file. If no device is specified, the system default will be used. If no filename is specfied, snapshot.jpg will be used. Supported image types: JPEG, TIFF, PNG, GIF, BMP -h This help message -v Verbose mode -l List available video devices -t x.xx Take a picture every x.xx seconds -q Quiet mode. Do not output any text -w x.xx Warmup. Delay snapshot x.xx seconds after turning on camera -d device Use named video device
To have a snapshot taken every five seconds, for example:
$ ./imagesnap -t 5 Capturing image from device "FaceTime HD Camera (Built-in)"...snapshot-00000-2013-04-17_18-02-09.623.jpg snapshot-00001-2013-04-17_18-02-14.625.jpg snapshot-00002-2013-04-17_18-02-19.629.jpg snapshot-00003-2013-04-17_18-02-24.632.jpg
Even better, you can see that ImageSnap is smart enough to name the files with a timestamp.
Realistically, every five seconds is probably too frequent. Try every 30:
$ ./imagesnap -t 30
With that, you should be good to go as a budding Mac cyber-detective. Come back and let us know how it went, okay!