O'Reilly logo

AppleScript: The Missing Manual by Adam Goldstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Image Events

Photoshop is the embodiment of pro image editing, but it's a memory and processor pig. If you'd like a very simple graphics program—one that works completely in the background—Mac OS X has your ticket. It's called Image Events , and AppleScript commands it with ease.

Open the Image Events dictionary (File Open Dictionary), and browse through the commands in the Image Suite. These commands cover all the manipulations you can make to your images: cropping, scaling, saving in various formats, and so on. The following pages provide just a few examples of what you can do with these commands.

Getting Image Dimensions

One of Image Events's simplest uses is getting the dimensions of any image on your hard drive. You'll find that helpful if you ever need to locate an image that's exactly 1024 768 pixels for your desktop background, for example.

Here's how to script the job:

--Part 1:
set selectedFile to (choose file)
--Part 2:
tell application "Image Events"
    set openedFile to open (selectedFile as alias)
    ---Part 3:
    set dimensionList to the dimensions of openedFile
    set fileWidth to the first item of dimensionList
    set fileHeight to the second item of dimensionList
    --Part 4:
    close openedFile
end tell
--Part 5:
display dialog "Width: " & fileWidth & " pixels" & return & "Height: " & ¬
    fileHeight & " pixels"

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required