Skip to Content

AppleScript: Taking screenshots



Last week, Dave mentioned that you can change the file type used system-wide for screenshots. However, some people are afraid of using Terminal.app to muck around with their Mac. In this week's AppleScript article, I am going to show you how to take screenshots and change their file type using an AppleScript.

The AppleScript
property N : 0
set N to N + 1
set picPath to ((POSIX path of (path to desktop)) & "Picture_" & N & ".png") as string
do shell script "screencapture -tjpg " & quoted form of picPath


Using the AppleScript
Open the ScriptEditor (/Applications/AppleScript/ScriptEditor.app). Copy/paste the AppleScript into the script edtitor and click the run button at the top. You will hear the camera shutter sound and a picture will be taken and saved to your desktop.

This script comes in handy when you want to take a screenshot in a different format. To do this, just change the ".png" file type to whatever you might want (say, .jpg, .tiff, etc.). When you re-run the script, the new file type will be associated with the capture image.


Continue reading to learn how to save this script.



Saving the AppleScript
You can save this script as an application in order to quickly take screenshots in the file type you want. To save the script as an appliction:
  1. Select File > Save As
  2. Select "Application Bundle" from the "File Format" drop-down box
  3. Click the save button


Update: The script has been updated to include "-tjpg" for the "screencapture" shell script. This allows the image file type to be changed temporarily. Thanks to a commenter for pointing out this error with the script! To change the file type, just replace " -tjpg " with "-tpng" (or your favorite image type).

Last week, Dave mentioned that you can change the file type used system-wide for screenshots. However, some people are afraid of using...
 

Add a Comment

*0 / 3000 Character Maximum

16 Comments

Filter by:
Shmaff

I randomly found GrabUp one day! Limited in functionality; however, very quick to use. Hit http://www.grabup.com. You'll find a very quick summary there.

July 08 2008 at 4:17 AM Report abuse rate up rate down Reply
Shmaff

I'm going to use my old iPhone as an e-mail server for my small business/family. We don't get _that_ many e-mails a day so it makes the perfect system to leave on all the time plugged in in the basement. It's power requirements are a fraction of that of a real server. I think it'll rock!

July 08 2008 at 4:13 AM Report abuse rate up rate down Reply
mark

Shocking how much investigating into the most difficult ways to take a screen shot is done at this site.

There's an apparently COMPLETELY UNKNOWN program called G R A B. It comes with your Mac. Investigate this.

July 07 2008 at 3:29 PM Report abuse rate up rate down Reply
Fernando

Hey, since you're on a screenshot mood, is there a way to take a timed screenshot of a window?

I currently have a script that activates the window I want, takes a screenshot then crops it with core image. There has to be an easier way.

I want to use it to monitor apps with big progress bars from away, like when I leave something huge downloading and want to check the progress from a pc with just IE (lol).

July 07 2008 at 2:39 PM Report abuse rate up rate down Reply
HandyMac

Why go to so much trouble? I use a lot of screenshots, mostly in the default .png format, but sometimes I want .jpg; so I just installed the Screenshots Pref Pane, which allows me to switch the format instantly, take the shot, then switch it back. The Macintosh way, no Terminal or AppleScript acrobatics needed.

July 07 2008 at 12:13 PM Report abuse rate up rate down Reply
1 reply to HandyMac's comment
HandyMac

P.S.:
http://www.ego-systems.com/Products/screenshotsprefpane.html

(For some reason, the system didn't accept my html.)

July 07 2008 at 12:15 PM Report abuse rate up rate down Reply
Michael

"However, some people are afraid of using Terminal.app to muck around with their Mac."

But these same people are not, apparently, "afraid" of using AppleScript to "muck around with their Mac". Why the disjunction?

I can't fathom why these "some people" about whom we hear so much on Mac sites are so frightened by shell scripts and yet completely comfortable with AppleScript. What a bizarre attitude! These are both just ways of interacting with the machine.

If anything OS X's AppleScript capability ought to give people who are liable to fear, and even those who aren't, more pause for thought - because of the nature of the open scripting architecture. This is what recent malware that exploits the ARDAgent's unfortunate default permissions relies on:

"OS X's implementation of AppleScript has a problem. ... The problem is: Applications that are running as root can accept AppleScript commands from applications that are not running as root. And since every Cocoa application automatically gets some basic AppleScript support, this means that any time a Cocoa application runs as root, anyone else can send it a 'do shell script' command and pretty much run anything they want as root."

http://forums.macnn.com/90/mac-os-x/370693/huge-crazy-ridiculous-os-x-security/

July 07 2008 at 11:49 AM Report abuse rate up rate down Reply
CZ

Or you could use the free Onyx program to handle this plus a variety of other changes in OS X.

July 07 2008 at 11:32 AM Report abuse rate up rate down Reply
Caitlin

Or. Use TinkerTool. It works wonders.

July 07 2008 at 11:14 AM Report abuse rate up rate down Reply
Caitlin

Use TinkerTool. Works wonders for me.

July 07 2008 at 11:11 AM Report abuse rate up rate down Reply
mbabco

There's a great utility -- Cocktail -- that lets you save screenshots in 1 of 11 different formats -- from BMP to TIFF (through GIF, JPEG, JPEG-2000, Photoshop, PICT, PNG, SGI, TGA). It's very useful for other things as well (cleaning caches, running CRON (maintenance) scripts, repairing permissions).

July 07 2008 at 10:49 AM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.