13.8. AppleEvents

Applications talk to each other through packets of information known as AppleEvents. When you send a command to an application, AppleScript composes an AppleEvent that consists of the command and its parameters. It then sends the event to the application and waits for a response. The application responds to AppleScript through another AppleEvent. The event may specify that it doesn't understand the command; or if it can handle the command, it will reply with the result (which may be an error), if any, after executing the command.

Here's an example: Suppose you ask the Finder to delete a file. AppleScript composes an event consisting of the command, which is delete, and its direct object, which is a file reference. Then it sends the event to the Finder and waits for a reply. The Finder gets the event and looks at what it's been asked to do. Because Finder understands the delete command, it handles the command itself. The file reference that is part of the event specifies the file to delete. If the file is successfully deleted, the Finder sends back an event to AppleScript containing the reference to the deleted file.

As you see in the next Try It Out, communication with scripting addition commands are also managed through AppleEvents. That includes the Standard Additions commands.

13.8.1.

13.8.1.1. Try It Out: AppleEvents in the Event Log History

To examine AppleEvents with Script Editor, follow these steps:

  1. Choose Script EditorPreferences.

  2. Select History from ...

Get Beginning AppleScript® 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.