Using Terms From
A terms block (as I call it) has the following structure:
using terms from application
-- code
end using terms from
A terms block dictates what
application’s
dictionary AppleScript should get the enclosed terminology from,
without actually targeting that application. On the usual principle
that the innermost block takes precedence, if multiple terms blocks
are nested, only the innermost terms block containing a given line of
code has any effect on that line. Similarly, a terms block overrides
the dictionary-seeking function of an enclosing tell block. A terms
block doesn’t override an enclosed
tell
, but if an enclosed tell
would not permit AppleScript to obtain a dictionary that it needs, a
terms block may do so.
Thus, this will not compile:
tell application "Finder"
using terms from application "Mailsmith"
get name of folder 1 -- compile-time error
end using terms from
end tell
The problem there is that AppleScript must seek
folder
in Mailsmith’s dictionary,
and doesn’t find it. But this will
compile:
using terms from application "Finder" tell application someVariable get name of folder 1 end tell end using terms from
AppleScript has no idea what someVariable
will be
at runtime, so it follows the instructions of the terms block and
thus is able at compile time to obtain a dictionary that resolves the
enclosed terminology. This, however, does not guarantee that the code
will run. Perhaps someVariable
will specify an
application that knows what a folder
is; perhaps ...
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.