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 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).
Share
Categories
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
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 Permalink rate up rate down ReplyI'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 Permalink rate up rate down ReplyShocking 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.
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).
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 Permalink rate up rate down ReplyP.S.:
http://www.ego-systems.com/Products/screenshotsprefpane.html
(For some reason, the system didn't accept my html.)
"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/
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 Permalink rate up rate down ReplyOr. Use TinkerTool. It works wonders.
July 07 2008 at 11:14 AM Report abuse Permalink rate up rate down ReplyUse TinkerTool. Works wonders for me.
July 07 2008 at 11:11 AM Report abuse Permalink rate up rate down ReplyThere'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 Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Refurb Apple MacBook Air Laptops: 12" 64GB SSD for $699 + free shipping
- JVC Motion Sensing Clock Radio with Dual iPod Docks for $55 + free shipping
- Apple iPhone Headset with Mic for $4 + $2 s&h
- miFrame Picture Frame Dock for iPad for $64 + $8 s&h
- Refurb Apple iPod nano 8GB MP3 Player for $99 + free shipping, 16GB for $119
- Hannspree Apple-Shaped 28" 1080p LCD HDTV for $270 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



16 Comments