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 ...

Get Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third 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.