Name

record

Examples

You can find out how many property/value pairs there are in a record by getting its length property, as in:

length of theRec

(which returns 2). You can change values by referring to the property name (unless the record is a read-only application property). You can also add to a record by concatenating another record to it:

get length of theRec -- returns 2
set subject of theRec to "AppleScript language"
set theRec to theRec & {users:"Mac scripters"}
get theRec (* returns {name:"AppleScript in a Nutshell", subject:"AppleScript 
language", users:"Mac scripters"} *)

You can coerce a record to a list type, but the record (now a list) will lose all of the property names. For example:

get theRec as list

will return:

{"AppleScript In a Nutshell", "AppleScript language", "Mac scripters"}.

Records can have expressions or variables as property values, as in the following example (however, you cannot use variable values for property names):

set myVar to "A variable"
set twoRec to {calc:(2 + 2.5), var:myVar} as record (* returns {calc:4.5, 
var:"A variable"} *)
set twoRec to {calc:(2 + 2.5), var:myVar,myVar: 7} as record (* returns 
{calc:4.5, var:"A variable",myVar: 7} and doesn't evaluate the myVar variable 
at the end of the record*)

You cannot use two-word property names when creating your own record. You will have to use capital letters or underscore characters to create more descriptive property names:

set climberName to {FirstName: "Edmund", last_name: "Hillary"}.

as opposed to:

set climberName to {First Name: "Edmund", Last Name: "Hillary"}.