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

Making Your Applications Scriptable

Previous | Chapter contents | Next | Book PDF

How a Command Is Composed and Executed

When the Apple event translator in the Yellow Box receives an Apple event that corresponds to a script command, it converts the Apple event (and associated data) to a script-command object (NSScriptCommand). Using the suite terminologies for all scriptable objects in the current application, the translator obtains the keys for these objects and uses them to extract data from the class descriptions and command descriptions loaded by that application (including suites of imported frameworks and loaded bundles).

With this data, it composes the script command. A script command has several components:

Because at this point the receivers and arguments are probably known only as AppleScript reference forms (for example, "word 5 of paragraph 3 of front document"), they are represented as nested "object specifiers" (that is, NSObjectSpecifier objects). The actual objects referenced by the object specifiers cannot be known until the command is executed within the context of the target application.

Once the Apple event translator has composed the script command, it sends the command to the application's NSScriptExecutionContext object, where it is executed. Command execution is not a simple procedure. It involves several steps:

  1. It evaluates the object specifiers in the script command to determine which objects are receivers and arguments (see " How an Object Specifier Is Evaluated " for details).
  2. It determines which method to use for executing the command. It first looks in the class description of the receiver to see if it has specified a selector for the command. If it doesn't, it selects the default implementation for the command.
  3. It calls the method indicated by the selector or the method implementing the default behavior for the command. This method has a single argument: the script command.
  4. It returns any return value to the Apple event translator, from where it eventually makes its way back to the originating script.

Making Your Applications Scriptable

Previous | Chapter contents | Next | Book PDF