beautypg.com

Simplifying recorded scripts 1 – Apple AppleScript Finder Guide User Manual

Page 20

background image

C H A P T E R 1

Introduction to Finder Scripting

8

Recording Actions in the Finder

After you run the new script, the windows have the views specified in the

script even if you’ve previously changed them.
To modify recorded scripts or create new scripts that control the Finder, you

may need to look up the definitions of some of Finder terms. Like any

scriptable application, the Finder contains a dictionary of the AppleScript terms

that you can use to control the application. To open the dictionary, drag the

Finder’s icon over the icon of the Script Editor, the script-editing application

that comes with AppleScript. If you run across an unfamiliar word in a

recorded script, you can look it up quickly in the dictionary. If you need a

comprehensive definition with examples, look up the term’s entry in this book.

Simplifying Recorded Scripts

1

As is often true of scriptable applications, the Finder allows you to express the

same action in several different ways. Recorded scripts are precisely worded

so as to avoid ambiguity in variety of circumstances. In the script shown in

Listing 1-1 on page 6, however, there is no need to specify the folder and

disk to which a window belongs. If you wish, you can specify a window by

name only:

set view of window "Letters" to size

To work correctly, the preceding statement must be contained in a Tell state-

ment that names the Finder as the target application, and the window named

Letters must be open. The container for a Finder window is always the Finder

itself. If more than one window named Letters is open, the Finder changes the

View property for all windows with that name to size.
The previous section described how to add three lines at the end of the script

shown in Listing 1-1 that set the window’s views to different values. If instead

you want all the windows opened by that script to have the same view, you

could add just one line:

set view of windows to name

The plural form windows identifies all open Finder windows.
After opening a window, the recorded script in Listing 1-1 adjusts the window’s

Position and Size properties separately. The terms Position and Size name

two different properties of a window. Each property consists of a list of two