Name

copy

Syntax

copy value to variableName
                  

Description

Assigns value to variableName.

Example

copy 5 to x

An abbreviation for copy is put ; an abbreviation for to is into. Thus you could type put 5 into x, although it would still come out as copy 5 to x. This is doubtless to accommodate HyperCard users, who were habituated to this syntax.

In these expressions, variableName can optionally be a list of variable names, allowing multiple assignments in one command. The value, too, will then be a list—a list of the values to be assigned. The first item in the value list is assigned to the first item in the variableName list, the second to the second, and so forth. If the value list is longer than the variableName list, the extra values are not assigned to anything; if the value list is shorter than the variableName list, there is a runtime error. This remarkably elegant feature is probably under-utilized by beginners. (For a parallel construction involving assignment to a record, see Section 13.13.) For example:

set {x, y, z} to {1, 2, 3}
z -- 3
                     , and can you guess what x and y are?

It sounds from their descriptions as if set and copy must be completely interchangeable. In most cases, they are; but with regard to four types of value—lists, records, dates, and script objects—they are not. This point will be covered in subsequent chapters. For other datatypes, you may use whichever command you prefer; I prefer set.

There is no simple assignment operator, such as equals sign (=). You cannot, ...

Get AppleScript: The Definitive Guide 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.