O'Reilly logo

AppleScript in a Nutshell by Bruce W. Perry

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

Chapter 5. Reference Forms

This chapter describes the AppleScript reference forms, or the ways that you can specify or refer to one or more objects in AppleScript code. First we will describe the ten different reference forms, then the rest of the chapter provides a reference to the actual AppleScript reserved words (e.g., every, thru, whose) that you can use to identify or refer to objects in your code.

Here are the ten different reference forms:

Arbitrary Element

Using the reserved word some, AppleScript code can grab a random object in a container. Here is an example:

tell application "Finder"
    (* get a random image file from a desktop folder *)
    set randomImage to some file of folder "jpegs"
end tell

See the section on some.

Every Element

This type of reference form specifies every object of a certain class type in a container, such as:

tell application "Finder"
    set allFiles to every file in folder "today" (*  returns a list
    of file objects *)
end tell

See the section on every.

Filter

The Filter reference form specifies objects based on certain attributes, such as all files whose name ends with .txt. The where and whose reserved words are used in Filter references. See the whose section.

ID

The ID reference form can be used to grab an object based on the value of its ID property (if it has an ID property, that is.) The ID reference form is expressed in code with the AppleScript id reserved word. See the id section.

Index

The popular Index reference form specifies an object based on its ...

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