Attributes

The second way in which values are object-like in AppleScript is that they can have attributes . A attribute is a named value belonging to the object. The most intuitive way to understand attributes is through the notion "has." A list has a length; a string has characters; a folder has a name; an iTunes track has an artist.

There are two important things to understand about attributes. First, attributes are values like any other values, which means they are themselves objects. There is thus a relationship between two objects as owner and attribute. The object that is the attribute may itself have attributes, and so we can end up with a vast chain or tree linking many objects. This structure is called an object model and is crucial to your understanding of how to talk to a scriptable application. Every scriptable application has an object model, which functions as your map of that application's world.

Second, attributes are accessible only through their owner. For example, iTunes has a huge object model representing all the tracks in all your playlists, and all the various attributes of those tracks; but there is only one object to which you have direct access—the iTunes application. All the rest of iTunes's object model belongs to iTunes, and to access any object in it, you have to ask iTunes. If this reminds you of how script objects and their top-level entities work, it should (see "Top-Level Entities" in Chapter 8).

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