6.2. Working with Records

You know that a list contains an ordered series of items. You can reference items in a list by number or by a range of numbers. So you can ask for the first item in the list, the 25th item in the list, or the 10th through 15th items in the list. You can also ask for every item in the list.

A record is, in some ways, similar to a list in that it enables you to collectively refer to a set of values. Whereas a list is a collection of items, a record is a collection of properties. A property consists of a name (or label) and a value that is associated with that name. Unlike a list, the properties of a record are not ordered and can only be referenced by name. These properties cannot be referenced by number or by beginning or end. You also cannot directly enumerate all the properties in a record.

6.2.1. Defining a Record

The general format of a record looks like this:

{ labell: valuel,  label2: value2        labeln: valuen }

The properties in this record are named labell, label2, . . ., labeln and have corresponding values valuel, value2, . . . valuen. Property names are formed by following the same rules for forming variable names that you learned about in Chapter 2. You can have a property with the same name as a variable in your program. AppleScript figures out your intentions based on the context in which the name is used.

As a simple example, the following defines a record that contains two properties called name and email with the corresponding values "Greg ...

Get Beginning AppleScript® 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.