It
The keyword it represents the target. (In situations where you would say of it after a word, you may say its before that word instead.)
The keyword it can be useful in helping you understand who the target is. It can also be useful as an explicit target, in situations where AppleScript would otherwise misinterpret your meaning.
This example shows it used while debugging, to make sure we understand who the target is:
tell application "Finder"
tell folders
it -- every folder of application "Finder"
end tell
end tellSometimes when you get yourself deep in a nest of tell blocks (see "The Chain of Ofs and Tells," earlier in this chapter), it can be helpful for referring to the target one level up. For example, this code opens file 1 of folder 1 and also opens folder 1 itself:
tell application "Finder"
tell folder 1
open file 1
open it
end tell
end tellYou have already seen ("Accessing Top-Level Entities" in Chapter 8) the need for it when accessing a script object's top-level entities within a tell block addressed to the script object. When targeting an attribute of a scriptable application, there is generally no need for it used in this way. Unlike a script object, an application has a dictionary, so AppleScript knows when you're saying the name of an attribute of that application. For example, the Finder has an attribute home; there is no need for its to tell AppleScript that we mean the Finder's home rather than a variable in scope:
set home to "Ojai" tell application "Finder" get home ...
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