Target
At every moment in AppleScript code, you are speaking to some object. That object is the target, to which, unless you specify otherwise, all messages will be sent. The target can be implicit, or you can specify an explicit target. 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. In this
code, the implicit target of set is the script
itself:
set x to 5
In this code, the implicit target of set is the
script object myScript:
script myScript
set x to 5
end scriptThere are two ways to specify an explicit target. Not coincidentally, they bear a strong resemblance to the two ways of accessing a script object’s top-level entities (Chapter 9). You can specify an explicit target:
With the
ofoperator or its synonyms. A synonym forofisin. (I never use this.) Another synonym, for most purposes, is the apostrophe-ess operator: instead of sayingxofy, you can sayy'sx.The
ofoperator specifies the target for just a single expression, and overrides all other targets, explicit or implicit.With a tell block. Instead of an actual block, one may apply
tellto a single command (Section 12.3), but this is still just a special case of a tell block.In the context of a tell block, the object specified in the announcement is the default target for everything you say. This can be overridden by specifying a different target, using either an embedded tell ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access