Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Cocoa Object Specifier Classes

AppleScript recognizes many types of references. For the standard reference forms, Cocoa defines subclasses of the abstract class NSScriptObjectSpecifier. These classes are shown in Table 6-1. Each of these object specifier classes deals with identifying objects in collections (NSArray objects).

These classes are unusual in that they provide one of the few examples where your application routinely creates instances of scripting classes defined by Cocoa. You do that in the object specifier methods for your scriptable classes. For more information on these and related classes, see also Table 9-2.

Table 6-1   AppleScript reference forms and corresponding object specifier classes

Reference forms

Cocoa Class

Description

Arbitrary

NSRandomSpecifier

Specifies an arbitrary object in a collection.

Example: any word, some document

Filter

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 whose name is "Letter to Santa Claus"

ID

NSUniqueIDSpecifier

Specifies an object in a collection by unique ID.

Example: window id 739

Index

NSIndexSpecifier

Specifies an object in a collection by index.

Examples: word 5, front document

Middle

NSMiddleSpecifier

Specifies the middle object in a collection.

Example: middle word of paragraph 2

Name

NSNameSpecifier

Specifies an object in a collection by name. See class documentation for evaluation mechanism.

Example: window named "Report"

Property,

Every

NSPropertySpecifier

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

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

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

It is unlikely that you will need to subclass any of these classes, as they already cover the standard set of valid AppleScript reference forms. However, if you do need to create a subclass, you must override the primitive method indicesOfObjectsByEvaluatingWithContainer:count: to return indices to the elements within the container whose values are matched with the child specifier's key. In addition, you may need to declare any special instance variables and implement an initializer that invokes the designated initializer of its superclass, initWithContainerClassDescription:containerSpecifier:key:, and initializes these variables.

In addition to the concrete subclasses of NSScriptObjectSpecifier shown in Table 6-1, Cocoa provides other classes that assist the object-specifier classes in evaluation. Instances of these classes help to indicate relative position and represent Boolean and logical expressions in which object specifiers are involved.

A script statement can also contain filter references, which identify objects in containers based on the conditions specified in Boolean expressions. These expressions can be linked together by logical operators (AND, OR, NOT) and return the appropriate true or false value. Filter references begin with the words whose or where, as in get words where color is blue or color is red and rectangles whose x position is greater than 45. These references can contain phrases such as is, is equal to or is greater than, as well as their symbolic equivalents (such as = and >).

Instances of the NSWhoseSpecifier class represent filter reference forms in Cocoa. These instances hold a “test” instance variable, which is an NSScriptWhoseTest object.

For information about these and related classes, see “Object Specifiers, Logical Tests, and Related Categories.”



< Previous PageNext Page > Hide TOC


Last updated: 2008-03-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice