Target
At every moment in AppleScript code, you are speaking to some object. That object is the target , to which all messages will be sent, unless you specify otherwise. Knowing what object is the target, and how to specify a desired target, is very important to your successful use of AppleScript.
The implicit target is the current script or script object. (See "Handler Calls, Commands, and Script Objects" in Chapter 8.) In this code, the implicit target is the script itself:
count
In this code, the implicit target is the script object myScript
:
script myScript count end script
There are three ways to specify an explicit target: as a direct object
of a command
, with a tell block, and with the of
operator or one of its synonyms. These three ways may be combined to specify the complete target. (If they remind you of ways you can talk to a script object and access its top-level entities, they should; see Chapter 8.)
Direct Object
Most commands take at least one parameter. The unnamed parameter that directly follows the name of the command is the direct object. In the absence of any other target information, the target can occupy the place of the direct object.
In this example, we see the count
message being sent to various targets, each of which interprets it in a different way:
script s on count return "1, 2, 3, ha ha ha" end count end script count s -- "1, 2, 3, ha ha ha" count "hello" -- 5 count {1, 2, 3} -- 3 count application "Finder" -- 32(the number of desktop items)
It is permitted ...
Get AppleScript: The Definitive Guide, 2nd Edition 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.