O'Reilly logo

AppleScript® Programming for the Absolute Beginner by Jerry Lee Ford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding a Handler’s Effect on Variable Scope

As has already been mentioned, a variable’s scope defines the location from within a script where a variable and its value can be accessed. You already know that variables defined within if and repeat statement code blocks are local to those code blocks, meaning that they cannot be accessed and do not exist outside of those code blocks.

By default, any variable declared inside an event handler is local in scope, meaning that it cannot be accessed outside of the handler. However, using the global command, you can explicitly declare variables as being accessible anywhere within an AppleScript, regardless of where they are declared.

Working with Local Variables

Any variables declared within a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required