Access Mac Camera by Command Line

By  on  
FaceTime HD Camera

With all of my recent command line tutorials, I've really gotten excited about the shell's simplicity and realized the true power of using the underlying technology of pretty UIs.  Since I work from home, I spend a lot of time on video calls, so when I started playing around with command line utilities like ImageMagick and ffmpeg, I instantly asked myself:  how can I take a photo with the Mac's camera from within the terminal?

It turns outs out OS X doesn't provide that access; a third party utility named ImageSnap is the best route to taking captures from command line.

Install ImageSnap

I like using Homebrew to manage installs:

brew install imagesnap

You can compile from source if you like, obviously.

Take a Photo

To take a photo using the default video input device (FaceTime HD Camera is the default in most newer Macs), simply execute this:

# Take image, let camera warm up 1 second
imagesnap -w 1 snapshot.png

You'll wait a brief second or two, your green camera indicator will light up, and will then quickly fade out.  The image will be saved to a snapshot.png file.

ImageSnap also has the functionality to take a photo every n seconds:

# imagesnap -t {x}:{yy} seconds
imagesnap -t 1 -w 1

The command above takes a photo every second until the process is killed.

While I looked for this ability out of curiosity, there are some great use cases for taking images from command line, like tracking your Mac if it's stolen or taking a photo upon invalid login.  Imagesnap is an incredible utility:  simple to use and doesn't try to accomplish too much!

Recent Features

  • By
    6 Things You Didn’t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

  • By
    Welcome to My New Office

    My first professional web development was at a small print shop where I sat in a windowless cubical all day. I suffered that boxed in environment for almost five years before I was able to find a remote job where I worked from home. The first...

Incredible Demos

  • By
    Create Custom Events in MooTools 1.2

    Javascript has a number of native events like "mouseover," "mouseout", "click", and so on. What if you want to create your own events though? Creating events using MooTools is as easy as it gets. The MooTools JavaScript What's great about creating custom events in MooTools is...

  • By
    Duplicate the jQuery Homepage Tooltips

    The jQuery homepage has a pretty suave tooltip-like effect as seen below: The amount of jQuery required to duplicate this effect is next to nothing;  in fact, there's more CSS than there is jQuery code!  Let's explore how we can duplicate jQuery's tooltip effect. The HTML The overall...

Discussion

  1. The utility requires a full installation of Xcode to compile this software. :P

  2. This is awesome, I didn’t know it but I’ve been looking for a utility like this for awhile now.

    Also, not to be a stick in the mud, but I’m sure you mean Facetime and not Facebook HD Camera ;)

  3. Eduardo

    I can’t install imagesnap even after installing homebrew..

  4. zalun

    I had to delay the snapshot for almost a second as photo was pure black.

    imagesnap -w 1
  5. Patricio

    is there anyway to record mac camera since terminal?

  6. JD

    Where do the images save?

  7. Crusty

    How to use Terminal to discover if any application is using my Facetime camera? With the command lsof I get all the application who request the process, but not which is using right now

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!