
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 AppleScriptYou 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:
- Select File > Save As
- Select "Application Bundle" from the "File Format" drop-down box
- 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).













Reader Comments (Page 1 of 1)
7-07-2008 @ 9:45AM
Tom Z said...
I love these tutorials. I bought my first Mac a couple of months ago (a 24" iMac) and greatly appreciate these mini-lessons which help me to learn more about my iMac and OSX!
Reply
7-07-2008 @ 9:52AM
Ed said...
Right, and people are going to be happier doing that than pasting two lines into Terminal?
Surely the point of using AppleScript is to make things easier, not harder?
Reply
7-07-2008 @ 10:17AM
Kevin said...
Skitch is really all you need! I use it almost daily.
Reply
7-07-2008 @ 10:21AM
Schnaks said...
This script does not change the image format of the screenshot. It’s just the name of the file; so you might end up with a PNG named “Picture_3.tiff”.
To change the image format you have to use the -t option, for example
screencapture -tjpg Picture_1.jpg
produces an JPEG. (and screencapture -tjpg Picture_1.png would also produce a JPEG, regardless of the extension in the file’s name)
Reply
7-07-2008 @ 11:09AM
Joe said...
I was thinking the same thing. This post is even worse than the previous one - while that one would result in you having png files as screenshots (keeping things as they were by default), this applescript will create a jpeg image file with a png extension!
7-07-2008 @ 11:11AM
Caitlin said...
Use TinkerTool. Works wonders for me.
Reply
7-07-2008 @ 11:14AM
Caitlin said...
Or. Use TinkerTool. It works wonders.
Reply
7-07-2008 @ 11:32AM
ZeroCorpse said...
Or you could use the free Onyx program to handle this plus a variety of other changes in OS X.
Reply
7-07-2008 @ 11:50AM
Mike said...
"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/
Reply
7-07-2008 @ 12:13PM
HandyMac said...
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.
Reply
7-07-2008 @ 12:15PM
HandyMac said...
P.S.:
http://www.ego-systems.com/Products/screenshotsprefpane.html
(For some reason, the system didn't accept my html.)
7-07-2008 @ 1:07PM
mbabco said...
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).
Reply
7-07-2008 @ 2:39PM
Fernando said...
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).
Reply
7-07-2008 @ 3:29PM
mark said...
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.
Reply
7-08-2008 @ 4:13AM
shmaff said...
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!
Reply
7-08-2008 @ 4:17AM
shmaff said...
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.
Reply