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 tellSee 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 tellSee 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
whereandwhosereserved words are used in Filter references. See thewhosesection.- 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
idreserved word. See theidsection.- Index
The popular Index reference form specifies an object based on its ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access