Developer Documentation
PATH  Mac OS X Documentation > Making Your Applications Scriptable

Making Your Applications Scriptable

Previous | Chapter contents | Next | Book PDF

How an Object Specifier Is Evaluated

When the Apple event translator composes a script command, it evaluates an AppleScript statement and converts any reference forms in it to a nested series of NSObjectSpecifier objects (or, simply, object specifiers). It packages these nested object specifiers as the receivers of a command and possibly as the arguments of the command. An application evaluates these object specifiers in its own context to discover the "real" objects so referenced.

A reference form is an expression such as:

words whose color is blue of paragraph 3 of front document

AppleScript recognizes many types of reference forms; the Yellow Box has subclasses of the abstract NSObjectSpecifier class for most of them.

Table 3. Reference Forms and Object Specifier Classes

Reference Form
Yellow Box Class
Description

Property

Every

NSPropertySpecifier

Specifies an attribute (property) or relationship (element) of an object.

Example: "color" (Property), "every graphic of the front document" (Every)

Index

NSIndexSpecifier

Specifies an object in a collection.

Examples: "word 5", "front document"

Range

NSRangeSpecifier

Specifies a range of objects in a collection.

Example: "words 5 through 10"

Relative

NSRelativeSpecifier

Specifies the position of an object in relation to another object.

Example: "before word 5"

Filter
Name

NSWhoseSpecifier

Specifies every object in a particular container that matches specified conditions defined by a Boolean expression.

Example: "words whose color is blue" or "document named `letter to Santa Claus'"

Arbitrary

NSRandomSpecifier

Specifies an arbitrary object in a collection.

Example: "any word"

Middle

NSMiddleSpecifier

Specifies the middle object in a collection.

Example: "middle word of paragraph 2"

Note: The ID reference form does not yet have a corresponding Yellow Box class.

Most object specifiers have a reference to their "container specifier"--that is, the parent object specifier that "contains" it in the object hierarchy; the resolution of the container specifier must occur to establish a context in which the current object specifier can be evaluated. An object specifier knows how to evaluate itself in the context of its container specifier. (An object specifier also knows its "child specifier"--that is, the object specifier it is a container for.) An object that has no container specifier is known as the "top-level specifier"; in most cases, the top-level specifier is the application itself.

  1. Evaluation of nested object specifiers

Evaluation starts with the top-level specifier and proceeds down the chain of object specifiers, evaluating and resolving each until it determines the identify of the final, nested "child" object. This object is a receiver (or receivers) of the command or one of the command's arguments. Key-value coding is used as the mechanism for evaluation: An object specifier queries its evaluated container (using the valueForKey: method or an extension of this method) for the value of the key associated with the object specifier. The key is typically something like "filename" or "windows." The value is the evaluated object, such as an NSString representing a file system path or an NSArray of NSWindow objects. If the object reference has a child reference, the evaluated object is used as the basis for the next query, made on behalf of the child reference. (See " Make Objects Responsive to Key-Value Coding " for an overview of key-value coding.)


Making Your Applications Scriptable

Previous | Chapter contents | Next | Book PDF