Inside an Apple Event

Here’s how it works when Script Editor compiles and executes the following code, which comprises a complete compilable script:

tell application "Finder" to sleep

This is what happens:

  1. The AppleScript component has to find out which Apple event lies behind the sleep command. The component knows that the Finder is one of the places it should look for these details, because the Finder is targeted by the tell statement:

    tell application "Finder"...
  2. Remember that sleep is an English-language term for putting the computer to sleep, but it is implemented as the sleep Apple event beneath the surface. Figure 1-4 shows the structure of the sleep Apple event.

    A sleep Apple event
    Figure 1-4. A sleep Apple event

    The AppleScript component discovers the attributes of the sleep Apple event (e.g., the event id) from a segment of the Finder file called the Apple event terminology extension ('aete') resource. The 'aete' resource maps the sleep script command to the Apple event depicted in Figure 1-4.

  3. The component then sends that Apple event to the Finder, which responds to sleep by powering down the computer.

Here is an explanation of the structure behind the Apple event in Figure 1-4.

Every Apple event is comprised of unique four-character codes that represent the:

  • Event class

  • Event id

  • Address of the target application

The event class represents a grouping of similar Apple events. The event id uniquely ...

Get AppleScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.