May 92 - APPLE EVENT OBJECTS AND YOU
APPLE EVENT OBJECTS AND YOU
RICHARD CLARK
With Apple events, Apple has opened the door for applications to control each other and
work collaboratively. However, before applications can communicate, they have to
agree on the commands and data they'll support. Apple event objects form the basis of
such a protocol--the Apple event object model. The object model is powerful, but still
a source of confusion for many developers. This article provides an overview of the
object model and answers several commonly asked questions, including "What is the
Apple event object model?" and "How do I support it?
One of the greatest strengths of the Macintosh--its graphical user interface--is also
the basis of one of its greatest weaknesses--the difficulty of automating routine or
repetitive tasks. "Give us batch files!" many users cried. The developers responded
with macro programs such as QuicKeys and Tempo, which handle many of the routine
tasks but can't always make a program doexactly what the user wants.
The problem is that macro programs are generally limited to manipulating an
application's human interface and have limited information about the state of the
application. This means that if some setting has been changed or something has been
moved, running a particular macro might not have the desired effect. In other words,
one Macintosh application cannot control another application reliably through the
target application's human interface.
For one application to control another application reliably, all of the following must
happen:
• The two applications must agree on a protocol for sending commands and
data and agree on the specific information to be sent across this connection.
• The controlled application needs to provide a rich enough set of commands
and sufficient access to its data so that meaningful work can be done.
• The protocols and command sets should be standardized so that many
different applications can work together.
On the Macintosh, Apple events and theApple Event Registry provide the standards that
allow applications to control each other reliably. The Apple event, a standard protocol
for sending commands and data between applications, was introduced as part of System
7. TheApple EventRegistry defines standard Apple event commands and two standard
data types--Apple event object andprimitive. Apple event objects describe an
application's internal data, and primitive types describe the data that can be sent
between applications. In essence, the Registry forms the basis for a standard language
that applications can use when sending or receiving Apple events.
One of the challenges in creating theApple Event Registry was to keep the set of
commands small while providing an adequate level of control between applications. The
Registry does this by allowing the same command to apply to different Apple event
objects within an application. The application of Apple events to Apple event objects is
commonly referred to as theApple event object model.
This article provides an overview of the object model and then discusses how you can
add object model support to your application. The fundamentals of Apple events are
given inInside Macintosh Volume VI.
OBJECT MODEL BASICS
The Apple Event Registry defines an application's programmatic interface as a series of Apple event objects, where each object belongs to a particular object class. Each
Apple event object is comprised of some data and a set of Apple event commands that
operate on that data. In a traditional object- oriented fashion, new classes are defined
by taking an existing class and adding new data and/or commands. Related classes are
grouped together intosuites.
The most commonly used objects (and their associated commands) are grouped together
into the Apple eventcore suite. The commands in the core suite, which include Create
Element, Delete, Get Data, and Set Data, cover the basic operations for any given
object. The Apple event objects defined within the core suite include documents,
windows, and the application itself. The core suite also includes some primitive classes
such as long and short integers, Boolean values, and text. Every object model-aware
application should support the core suite, and all Apple event objects defined within
your application should support the core suite events.
The data portion of an Apple event object is broken into two parts: the
object'sproperties and itselements:
• Theproperties of an object contain the attributes of the object--for
example, its name and a 4-byte code designating its class.