Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


Secretly capture screenshots on my Mac?

When I used to work on a Linux system, there was a utility we had that would let me take screen captures every 30 seconds while my computer was otherwise unattended, as a way to see if anyone else was using it or not. I liked it. Now I'd like to do the same on my Mac system. Possible?


Dave's Answer:

Well, Mr. Bond, it sounds like some good spy software for a computer in the SMERSH offices, but perhaps that's not your intention. Still, it opens up a bit of a can of worms if you are letting others use your computer while you're running any sort of spyware or monitoring software that actually tracks and stores their action.

That's not exactly what you're asking me, but it's not hard to subvert the script I'll share for that purpose. Then again, guns don't kill people, bullets do. Um. Nevermind.

Anyway, yes, if you are willing to write a short shell script that you'd run in Mac's Terminal application, it's quite doable.

The key is a program called screencapture.

To see how to use it, you can simply type its name into Terminal directly with "--help":

$ screencapture --help
usage: screencapture [-icMPmwsWxSCUtoa] [files]
  -c         force screen capture to go to the clipboard
  -C         capture the cursor as well as the screen. only in non-interactive modes
  -d         display errors to the user graphically
  -i         capture screen interactively, by selection or window
               control key - causes screen shot to go to clipboard
               space key   - toggle between mouse selection and
                             window selection modes
               escape key  - cancels interactive screen shot
  -m         only capture the main monitor, undefined if -i is set
  -M         screen capture output will go to a new Mail message
  -o         in window capture mode, do not capture the shadow of the window
  -P         screen capture output will open in Preview
  -s         only allow mouse selection mode
  -S         in window capture mode, capture the screen not the window
  -t image format to create, default is png (other options include pdf, jpg, tiff and other formats)
  -T Take the picture after a delay of , default is 5
  -w         only allow window selection mode
  -W         start interaction in window selection mode
  -x         do not play sounds
  -a         do not include windows attached to selected windows
  -l capture this windowsid
  files   where to save the screen capture, 1 file per screen
That's a lot of data to absorb. The key flags are "-tfmt" to specify the output format and "-x" to disable the screen capture sound. You can add a time delay, but we'll do that with a looping structure in the shell itself so that it's reinvoked every "n" seconds.

Kind of like this:

while true ; do
   sleep 30
   screencapture -tpng -x capture.$(date +%F-%T).png
done

There are more graceful ways to come up with an incrementing filename, but we're just using date and time so that a typical resultant filename might be capture.2012-04-15-16:24:25.png.

Want to take a screen cap every 15 second or five minutes? Just change the sleep variable.

To use this, simply type the above into the Terminal -- I recommend moving into a new subdirectory first so that the screencaps don't take over the Desktop -- then minimize the Terminal window and walk away. As long as they don't kill the shell, it'll diligently keep taking a screen capture every "n" seconds until you either run out of disk space (not good) or kill it.

Done capturing? Just open up the Terminal window again and press Ctrl-C.

Now, use this wisely and appropriately, please.


More Useful Mac OS X Help Articles:
✔   Audacity can't find LAME library, I can't save Mp3?
Hey Dave. I read your article Audacity can't save mp3 audio files and am still puzzled because I downloaded the LAME Mp3 converter...
✔   How to remove Dashboard as a "space" in Mac OS X Spaces?
I'm a big fan of the Spaces utility in Mac OS X that lets me have multiple virtual screens [see Set Up Mac...
✔   Best place to buy a cheap MacBook laptop?
Hi Dave. I am looking for two gently used MacBook laptops for my teen daughters. Personal computers would greatly facilitate their studies as...
✔   File too big error copying to USB flash drive on my Mac?
I'm baffled. I have a 16GB Kingston USB flash drive that I use on my Mac system and I'm trying to copy a...
✔   Stealth image capture photo from webcam on my Mac?
Someone sneaks into my cubicle while I'm at lunch and takes candy out of my desk. Petty, but stupid too. I want to...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  





Categorized: Mac OS X Help , Shell Script Programming   (Article 10325, Written by )
Tagged: command line, linux, mac os x, shell script programming, terminal, unix
Previous: How to Host a Twitter Chat with TweetGrid
Next: Review: Logitech Cube mouse




Reader Comments To Date:

Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!
Rather amazingly, there are no comments on this article yet.

I do have a comment, now that you mention it!











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.