Kinds of Variable

With regard to scope, we must distinguish four kinds of variable:

Top-level entities

Top-level entities are script properties declared, and script objects and handlers defined, at the top level of a script or script object. (See "Top-Level Entities" in Chapter 8.)

Explicit locals

An explicit local is a variable announced by a local declaration , which looks like this:

local x
Explicit globals

An explicit global is a variable announced by a global declaration, which looks like this:

global x
Undeclared variables

A undeclared variable is none of the above. It's just a name that your code suddenly starts using. This is legal, but when you do it, AppleScript assigns the variable a scope , in ways that may surprise you.

The scope of a variable, and what kind of variable it is (these amount to the same thing), are determined at compile time .

Get AppleScript: The Definitive Guide, 2nd Edition 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.