Understanding Messages and Events


Macintosh applications perform tasks in response to events. Users originate events with the keyboard and mouse, and applications respond to the events by performing tasks. Similarly, an application can make other applications perform tasks by sending messages about events.

The events that applications send to each other in messages are called Apple events. AppleScript makes applications perform tasks by sending them Apple events.

When an application receives a message about an Apple event, the application takes a particular action based on the specific event.

This action can be anything from performing a menu command to taking some data, manipulating it, and returning the result to the source of the Apple event message.

For example, when you choose Shut Down or Restart from the Apple menu, Mac OS X sends an Apple event message to every open application saying a Quit event occurred. For this reason, applications quit automatically when you choose Shut Down or Restart.

When you drop document icons on an application icon, the Finder sends a message to Mac OS X saying this event happened, and the system sends the application an Apple event message that says an Open Documents event occurred. The Open Document message includes a list of all the documents whose icons you dragged and dropped. When you double-click an application icon, the Finder sends the system a message that says this event happened, and the system sends the application an Open Application message. When you double-click a document, the application that created the document gets an Open Documents message with the name of the document you double-clicked.

Virtually all Mac applications respond to at least four Apple events: Open Application, Open Documents, and Quit Application. Applications that print also respond to the Apple event Print Documents. Only very old, very specialized, or poorly engineered Mac applications don’t respond to these basic Apple events.

Applications that go beyond the four basic Apple events understand another two dozen core Apple events. These Apple events encompass actions and objects that almost all applications have in common, such as the Close, Save, Undo, Redo, Cut, Copy, and Paste commands. Applications with related capabilities recognize still more sets of Apple events. For example, word processing applications understand Apple events about text manipulation, and drawing applications understand Apple events about graphics manipulation. Application developers can even define private Apple events that only their applications know.

Mac OS X provides the means of communicating Apple event messages between applications. The applications can be on the same computer or on different computers connected to the same network. To understand how Apple event messages work, think of them as a telephone system. Mac OS X furnishes a telephone for each application as well as the wires that connect them. Applications call each other with messages about Apple events.

Apple events offer many intriguing possibilities for the world of personal computing. No longer does one application need to handle every possible function; instead, it can send Apple event messages to helper applications. For example, iTunes handles some commands in its File menu, such as Export Song List, by sending Apple event messages to the Finder, which actually carries out the commands.

start sidebar
Some Classic Programs Cannot Receive Apple Event Messages

In the Classic compatibility environment, only application programs can send and receive Apple event messages; true control panels and desk accessories cannot, although these items are now uncommon. Control panels that are actually applications (listed in the Classic environment’s Applications menu when open) are not subject to this limitation. And a desk accessory can work around this limitation by sending and receiving through a small surrogate application that is always open in the background. This background application does not have to appear in the Classic environment’s Application menu, and the computer user does not have to know that the application is open.

end sidebar




Mac OS X Bible, Panther Edition
Mac OS X Bible, Panther Edition
ISBN: 0764543997
EAN: 2147483647
Year: 2003
Pages: 290

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net