Basics of AppleScript

Local Variables

Script [14.5.1]:

set x to 5
on compute()
    set y to 10 * x
end compute
compute()

Explanation: The above script will generate error on calling the handler named compute(). This is because variable x has been declared outside the handler compute() but we are using it inside. compute() does not know anything about variable x. Hence error gets generated.

Figure 14.5.1

Figure 14.5.1 Local Variable

So anything declared inside the handler is local to the handler only i.e. if variable x is declared in the handler than the value of x will be local to the handler only. It cannot be called outside the handler.

e.g.

on compute()
    set y to 10
end compute
compute()
get y

Figure 14.5.1-2

Figure 14.5.1-2 Local Variables in Handler