Who Performs an Operation
Some operations within an
interapplication communications context can be performed by the
target application rather than AppleScript. There are two cases to
consider. The operation may appear as a bare expression (for example,
the condition in an if
clause); I will call this a
direct operation. Or, the operation may be
part of a boolean test element specifier.
Direct Operations
According to Apple’s documentation, if the first operand of a direct operation is a reference to an object of the target application, the target application performs the operation. So, for example:
tell application "Finder" if the name of folder 1 contains "e" then
The comparison performed by the keyword contains
is one of the operations that can be performed by the target
application. The object the name of folder 1
is a
Finder object, so in this case the Finder should perform the
operation. In fact, though, experimentation shows that the Finder
does not perform the operation; AppleScript does
try to get it to do so, but the target application replies with an
error indicating that it doesn’t wish to perform
that sort of operation. AppleScript thereupon adopts a new strategy:
it asks the target application for the values in question, and
performs the operation itself.
So, the way AppleScript first tries to deal with the operation in the
previous example is by sending the Finder a single Apple event that
means: “Please tell me whether the name of your
folder 1 contains "e
“.” The Finder ...
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.