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
    7 Essential JavaScript Functions

    I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent.  Times have changed but there are still a few functions each developer should...

  • By
    Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven...

Incredible Demos

  • By
    Using MooTools For Opacity

    Although it's possible to achieve opacity using CSS, the hacks involved aren't pretty. If you're using the MooTools JavaScript library, opacity is as easy as using an element's "set" method. The following MooTools snippet takes every image with the "opacity" class and sets...

  • By
    Google-Style Element Fading Using MooTools or jQuery

    Google recently introduced an interesting effect to their homepage: the top left and top right navigation items don't display until you move your mouse or leave the search term box. Why? I can only speculate that they want their homepage as...

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!