20.1. Resolution of Terminology
Example 20-1 exhibits some common patterns of terminology usage. With it, we'll model AppleScript's interaction with dictionaries during the process of compilation.
Example 20-1. Simple terminology resolution
tell application "Finder" set c to display dialog ((count folders) as string) end tell
Compilation of code like Example 20-1 proceeds in two distinct stages:
Let's consider these stages one at a time.
20.1.1. Loading the Dictionary
As AppleScript's compiler encounters a tell block (or a terms block) targeting a literal application, it attempts to locate this application and load its dictionary. If the compiler can't find the application, it will ask the user where it is; if the
AppleScript will proceed happily at this point, provided that it can find the application, or the user chooses an application for it any application. The compiler has not yet reached the stage of trying to resolve any actual terminology, so it doesn't matter whether there is any terminology to resolve, or even whether the application has a dictionary. All that matters so far is that the application referred to in code should be identified with some actual application.
Loading a dictionary takes time, and may even require launching the application in question, which takes even more time. Once the current instance of the AppleScript scripting component has already loaded a particular application's dictionary, however, it doesn't need to do so again, because it now has a copy of the dictionary cached in memory. These are some of the reasons why a script typically takes longer to compile the first time.
20.1.2. Translating the Terms
Presume that the compiler has reached the interior of the innermost tell block or terms block that caused a dictionary to be loaded. The compiler now proceeds to resolve the actual terms of the block.
22.214.171.124. The innermost application dictionary
Only one application dictionary is involved in the resolution of terminology in a given context. This is the dictionary corresponding to the innermost
The interaction between nested terms blocks and tell blocks in determining the target and the innermost application dictionary was described in Chapter 11 and Chapter 19. Recall that iTunes is not
tell application "iTunes" tell application "Finder" count folders end tell end tell
So iTunes's dictionary will be loaded at compile time (and this will necessitate launching iTunes if it isn't running already) but it will not be consulted because it isn't targeted. iTunes
tell application "Finder" using terms from application "iTunes" count folders -- error: The variable folders is not defined end using terms from end tell
The terms block deliberately perverts AppleScript's use of dictionaries. AppleScript, instructed explicitly to look in iTunes's dictionary, never learns that
is defined in the Finder's dictionary, nor does it find
in iTunes's dictionary. Thus it thinks
126.96.36.199. Hunting for each