The linguistic construction commonly used to perform communication with a scriptable application is the tell block. For example:
tell application "TextEdit"
activate
set word 1 of document 1 to "Hello"
end tell
In that code, the indented lines are within a tell block targeting TextEdit. Thus, TextEdit is their tell context.
Nested tell blocks can work their way down the object model hierarchy to narrow the tell context still further. For example:
tell application "TextEdit"
activate
tell document 1
set word 1 to "Hello"
end
end
In that code, the set
line’s tell context is document 1 of TextEdit.
Script Debugger watches as you work, and knows what the tell context of the current selection or insertion point is. This knowledge is fundamental to certain Script Debugger features. For example:
The tell context inspector explores the elements and properties of the targeted application relative to the current tell context.
The dictionaries inspector can search in the current tell context. So, if you select “word” in the above code and choose Search > Look Up Definition, and if the dictionaries inspector search options are set to Search in Tell Target, Script Debugger will search for the term word
in TextEdit’s dictionary.
The File > Open XXX Dictionary menu item knows what dictionary to open based on the tell context.
The tell context itself may depend upon the value of a variable at a given moment. Script Debugger handles this situation correctly, though the results may surprise you. For example:
on doTell(x)
tell application x
get window 1
end tell
end doTell
doTell("Finder")
Suppose this script is paused (in debug mode) at the line get window 1
. What should the tell context be if we click in that line? Well, there are two stack frames: the doTell
handler call, and the top level of the script (the implicit run handler). In the stack frame of the doTell
handler call, x
has a value and there is a tell context (the Finder). But in the stack frame of the top level of the script, x
has no value and there is no tell context (and the tell context inspector will report “no selected tell block”). So the tell context depends upon the selected stack frame as well as the current selection.