Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Programmer's Guide to MacApp / Part 1 - MacApp Theory and Architecture
Chapter 6 - Scripting


Overview

The Macintosh Operating System provides the capability of using high-level events to communicate between applications, to control applications, to allow users to automate tasks, and even to allow sophisticated users to modify an application's behavior. This capability is based on the Open Scripting Architecture and the use of Apple events.

To help explain the scripting support MacApp supplies, the following sections describe basic scripting terminology and examine the levels of scripting support an application may provide. For a more detailed description of scripting, refer to Inside Macintosh: Interapplication Communication.

Scripting Terminology

Apple Computer has defined the Open Scripting Architecture (OSA)--a standard mechanism that allows users to control multiple applications with scripts written in a variety of scripting languages. Each scripting language has a corresponding scripting component. The AppleScript component implements AppleScript, the standard user scripting language defined by Apple Computer. By default, MacApp uses the AppleScript scripting component.

An Apple event is a high-level event that conforms to the Apple Event Interprocess Messaging Protocol. The Apple Event Manager uses the Event Manager to send Apple events between applications on the same computer or between applications on remote computers. An application is called a server when it responds to Apple events sent by another application. The sending application is referred to as the client.

The Apple event object model defines a standard interface that allows an application to be controlled from other applications and to be scriptable using standard, human-language terminology. A script is a collection of data that, when executed by the appropriate program, causes a corresponding action or series of actions.

An Apple event object is a distinct item (such as a word, paragraph, shape, window, or style format), in an application or its documents, that can be specified by an object specifier record in an Apple event. The Apple Event Manager allows applications to construct and interpret object specifier records by means of a standard classification system for Apple event objects. The Object Support Library (OSL) is a component of the Apple Event Manager; applications use the OSL to create and resolve object specifier records.

The Apple Event Registry: Standard Suites defines the standard suites of Apple events, which are groups of related events that are usually implemented together. The standard suites include the following:

An Apple event terminology extension resource, of type 'aete', provides information to a scripting component about the Apple events an application supports and about the human-language terminology associated with those events.

Factoring an application (see page 143) is a two-part process that involves

There are three well-defined levels of scripting support an application can provide:

Most applications should be scriptable and recordable. Consider making your application attachable if it will need to be very flexible or customizable.

Scripting and recording are closely related. A scriptable application can respond to Apple events sent to it from any source. A recordable application handles an Apple event that it sends to itself the same as if it were sent from an external source--by performing the operation requested by the user. This implies that recordable applications must be scriptable.

Note
To help support scripting in your application, MacApp provides a mechanism for creating command objects that can both perform an operation and supply an Apple event that describes that operation. For more information, see "Command Objects and Apple Events," beginning on page 120.
MacApp predispatches Apple events to attached scripts before dispatching them to the application's scriptable objects. For more information, see "Dispatching Apple Events," beginning on page 150.

Deciding What Level of Scripting to Support

During the design of your application, you determine what level of scripting support the application will provide. Here are some of the basic questions you need to answer:

Required and Core Event Suites

Every application should support the four Apple events in the Required suite, since these events may be sent to the application by the operating system. Many applications support additional events from the Core suite to specify operations such as getting and setting data, moving and deleting objects, and counting objects of a particular type. MacApp automates support for the Required suite and supplies substantial support for the Core suite as well.

Area Suites

Depending on its function, your application may also want to support Apple events from other suites, such as the Database, Mail, and Text suites. For more information on Apple event suites, see "Identify the Custom Apple Event," beginning on page 361.

Factoring

Factoring your application plays a key role in providing scripting support. If you thoroughly separate user interface code from code that responds to user actions, and if you perform operations as individual tasks, it will be much easier to use Apple events to initiate and record actions. It will also be easier to use scripts to manipulate your application in a powerful and comprehensive way. Factoring can be a useful design goal for cross-platform development, even if your application has minimal scripting support.

MacApp itself is factored through the use of command objects. When a user manipulates the user interface to perform a task, MacApp creates a command object to perform the specified operation. A command can send an Apple event that describes its command operation, making it easy to record the operation or to allow an attached script to respond to the Apple event.

Advantages and Disadvantages of Adding Scripting Support

There are a number of reasons to factor your application and support scripting for various Apple events:

The use of embedded scripts (those built in at the program development stage) and attached scripts (those that can be added or modified after the application is built) can offer additional advantages:

But there are also costs associated with writing a fully factored program that supports a large number of Apple events and uses embedded or attached scripts:


Previous Book Contents Book Index Next

© Apple Computer, Inc.
25 JUL 1996