Cocoa Scripting Classes and Categories
The tables in this chapter provide brief descriptions for the listed Cocoa scripting classes. The accompanying material provides information on when your application uses these classes, as well as hints on which ones you might need to subclass.
About thirty public classes in Cocoa's Foundation framework support the basic structure of Cocoa scripting. Several methods in the Application Kit framework add scriptability features for applications, windows, documents, and text objects. Together, this provides support for the AppleScript commands listed in Summary of AppleScript Command Support (such as get
, set
, move
, delete
, and so on).
In many cases, Cocoa scripting creates and manipulates instances of these classes, such that your application needs only to respond when a method of a particular application object is invoked. That is, your application rarely needs to declare or instantiate any of the basic Cocoa scripting classes.
On the other hand, some applications will need to define subclasses of one or more of Cocoa scripting's command classes to provide support for operations specific to the application. Even in those cases, however, the application is not responsible for creating instances of the commands—Cocoa scripting does that, based on the scriptability information provided in the application's sdef file. The process of working with commands is described in detail in Script Commands.
There is one case where your application typically creates instances of Cocoa scripting classes. In object specifier methods for your scriptable classes, you'll create instances of the object specifier classes listed in Table 9-2.
Script Commands and Scriptability Information
The following classes provide the base class for script commands, the context in which commands are executed, and the scriptability information associated with an application. Instances of these classes are created automatically by the Cocoa scripting, in a process described in Script Commands Overview. Except for NSScriptCommand
, most applications will not need to subclass or even call methods of these classes.
Class | Description |
---|---|
A shared instance of this class loads and registers the scriptability information associated with an application, whether from sdef files or the older script suite and script terminology files. Provides methods to get loaded suites, class descriptions, and command descriptions, but applications rarely call these methods. | |
Abstract class that provides the interface for querying the properties of a class. Instantiated by the global instance of | |
A subclass of | |
A subclass of | |
Encapsulates an AppleScript command sent to an application as an Apple event. Uses its methods to evaluate object references (receivers and arguments) and execute the command. Cocoa scripting subclasses for the major AppleScript commands are described in Table 9-4. You can create your own subclasses to handle operations specific to your application. For more information, see Object-first Versus Verb-first Script Commands. | |
Represents the context in which an AppleScript command is executed and tracks global state related to that command. You do not need to subclass this class. |
Object Specifiers, Logical Tests, and Related Categories
NSScriptObjectSpecifier
, an abstract class. Instances of these classes—object specifiers—know how to evaluate themselves within the context of a container object specifier. Some of these classes represent relative or logical tests performed with object specifiers (particularly NSWhoseSpecifier
objects).
These are among the few classes provided by Cocoa scripting that your application routinely instantiates. It does so when creating object specifiers. You shouldn’t need to subclass these classes, but you will need to implement some of the methods in the described categories, particularly in providing object specifier methods for your scriptable objects. For detailed information, see Object Specifiers.
Class or category | Description |
---|---|
An abstract parent class for subclasses that represent AppleScript references. An object specifier knows how to evaluate itself (to actual objects) in the context of a container specifier. | |
A subclass of | |
A subclass of | |
A subclass of | |
A subclass of | |
A subclass of | |
A subclass of | |
A subclass of | |
A subclass of | |
A subclass of | |
A subclass of | |
Category on | |
A subclass of | |
A subclass of | |
An abstract class for objects that represent Boolean expressions (qualifiers) involving object specifiers (also called | |
Category on | |
Category on |
Key-Value Coding and Value Coercion
The following perform essential functions related to scripting. For information on the use of these classes, see Key-Value Coding and Cocoa Scripting and Coercion.
Class or category | Description |
---|---|
A shared instance of this class coerces object values to objects of another class, using information supplied by classes who register with it. Coercions frequently are required during key-value coding. For more information, see Coercion. | |
Category on |
Subclasses for Standard AppleScript Commands
The following classes implement standard AppleScript commands. They are all subclasses of NSScriptCommand
, which is described in Table 9-1. Your application can create a subclass of one of these classes to replace the default behavior, or to selectively modify that behavior in some circumstances. In most cases, the default behavior should be sufficient.
For more information on working with commands, see Script Commands.
Class | Description |
---|---|
Copies the specified scriptable object or objects (such as words, paragraphs, images, and so on) and inserts them in the specified location. This class handles the | |
Closes the specified scriptable object or objects—typically a document or window. | |
Counts the number of items of a specified class in the specified object container (such as the number of rectangles in a document). | |
Creates the specified scriptable object (such as a document or graphic), optionally supplying the new object with the specified attributes. This class handles the | |
Deletes the specified scriptable object or objects. | |
Determines whether a specified scriptable object, such as a word, paragraph, or image, exists. | |
Gets the specified value or object from the specified scriptable object. For related information, see Getting and Setting Properties and Elements. | |
Moves the specified scriptable object or objects. For related information, see Modifying a Standard Command. | |
Quits the specified application. | |
Sets one or more attributes or relationships of the specified scriptable object to one or more values. For related information, see Getting and Setting Properties and Elements. |
Manipulation of Apple Events
You can use the following classes to directly manipulate Apple events and the data structures they contain. However, you can make your application scriptable with little or no direct use of these classes.
Class | Description |
---|---|
Represents a descriptor, the basic building block for Apple events. Descriptors can consist of arbitrarily nested lists of other descriptors. Every Apple event is itself a descriptor and is made up of descriptors. For information on the underlying structure of descriptors, see Building an Apple Event in Apple Events Programming Guide. | |
Provides access to a small set of Apple Event Manager features. Used primarily for directly registering Apple event handlers and for suspending and resuming Apple events (described in Suspending and Resuming Apple Events and Script Commands). For background information, see Apple Event Manager Reference and Apple Events Programming Guide. | |
Copyright © 2008 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2008-03-11