Chapter 10. Objects

Earlier chapters have quietly introduced the notion of sending messages to objects. In Section 8.5.1, and in Section 9.4, a script object was treated as “an object to which one can send messages,” with a handler call being such a message. In Section 9.3, we spoke of “sending the run message to a script object.” The object to which a message is sent was called its “target.” Section 9.7 depended upon the idea of a message being sent to a particular target. In Chapter 7, and again more fully in Chapter 9, we described the use of the of operator (or apostrophe-ess operator) or a tell block to specify a target and send it a message. It is now time to formalize these notions.

A message originates as an imperative verb, a command of some sort. But there is a distinction to be drawn between a command and a message. The command is what you say in code. The message is the communication of that command to some target, which is supposed to obey the command. For example, count is a command, and in a certain context it can cause the count message to be sent to the Finder, while in some other context it can cause the count message to be sent to Mailsmith. An object is anything that can be targeted by a message.

Sending a message to a target object is the fundamental activity of all AppleScript code; everything that is said in AppleScript code involves some target object to which some message is being sent. Furthermore, every value in AppleScript can act as such a target. ...

Get AppleScript: The Definitive Guide 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.