Language Guide

CHAPTER 8
Handlers
Scope of Script Variables and Properties 261
run Norah --result: 1
run Norah --result: 2
theCount --result: 2
theCount of Norah --result: 20
This script declares two separate theCount properties: one at the top level of
the script and one at the top level of the script object Norah. Because the script
Joe declares the global variable theCount, AppleScript looks for theCount
at the top level of the script, thus treating Joe’s theCount and theCount at
the top level of the script as the same variable.
If the script object Joe in the preceding example doesn’t declare theCount as
a global variable, AppleScript treats Joe’s theCount and the theCount at the
top level of the script object Norah as the same variable. This leads to quite
different results, as shown in the next example.
property theCount : 0
script Norah
property theCount : 20
script Joe
on increment()
set theCount to theCount + 1
return theCount
end increment
end script
tell Joe to increment()
end script
run Norah --result: 21
run Norah --result: 22
theCount --result: 0
theCount of Norah -- result:22