Creating a Simple Script

An easy way to see how a script looks and works is to type a simple script into a new script window. If AppleScript Editor is not already the active application, open it or switch to it. If you need to create a new script window, choose File⇒New or press Command Key+N. In the script-editing area at the bottom of the new script window, type the following statements:

tell application “Finder”

activate

set the bounds of the first Finder window to {128, 74, 671, 479}

set the current view of the first Finder window to icon view

set the icon size of the icon view options of the first Finder window to 32

select the first item of the first Finder window

end tell

Check your script for typographical errors by clicking the Compile button in the script window. If AppleScript Editor reports an error, carefully compare the statement you typed in the script window to the same statement in the book. Pay particular attention to spelling, punctuation, omitted words, and omitted spaces.

When you click Compile, AppleScript Editor formats your script, changing the text formatting as it compiles the script using different type styles to show different kinds of terms. The statements that you typed probably changed from Courier font to Verdana font after you clicked Compile. AppleScript Editor normally formats text that hasn't been compiled as 10-point Courier. Most other words, including ...

Get OS X Mountain Lion Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.