It
The keyword it
represents the target. This 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. In situations where you would say of it
after a word, you may say its
before that word
instead.
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 tell
We have already seen (Section 9.2.1) the need for
it
when accessing a script
object’s top-level entities within a tell block
addressed to the script object. Without it
, this
code fails:
script myScript
property x : 5
end script
tell myScript
display dialog x -- error
end tell
There is no x
in scope, so
there’s a runtime error. Similarly, if there were an
x
in scope, AppleScript would identify this
x
with that x
, rather than with
myScript
’s property
x
, unless we use it
:
script myScript property x : 5 end script set x to 10 tell myScript display dialog its x -- 5 , but 10 if we omit its end tell
When
targeting an application, however, there is generally no need for
it
used in this way. That’s
because, unlike a script object, an application has a dictionary, so
AppleScript knows when you’re saying the name of a
property of that application. For example, the Finder has a property
home
; there is no need for its
to tell AppleScript that we mean the Finder’s
home
rather than a variable ...
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.