O'Reilly logo

Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition by Hanaan Rosenthal, Hamish Sanderson

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

Chapter 11. Storing Objects in Variables

Often, a script will create objects that it needs to use again later. Obviously, what the script needs is some way to store those objects and then retrieve them when they're needed. AppleScript's variables provide just such a storage system.

Variables consist of two parts: the identifier and the value. The identifier is a name that describes the value, and the value is the object you actually want to use. Here's an example:

set first_name to "Sponge"

This example assigns the value "Sponge" to the variable first_name. If you want to retrieve the value of that variable somewhere else in the script, you use the identifier first_name. When the script is run, AppleScript evaluates the variable's identifier and ...

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