Standard Commands

The standard commands are basic events that should be implemented by any scriptable application. The only standard command implemented by AppleScript itself is count (with strings, lists, and records; see Chapter 13).

The count command is implemented in an unusual way. The class represents the element that is to be counted; it is optional, and most users prefer the second or third formulation if it is to be specified. (So, one tends to say "count items of L" rather than "count L each item.") If it is not specified, then it is up to the target to supply a default element and count it. Users tend to be unconscious of this fact. For example, when you say "count s," where s is a string, you're probably not aware that AppleScript is reinterpreting this as "count s each character." That's because character is the default element for a string; you could also specify a different element ("count words of s"). This syntax is sometimes the cause of misunderstandings, especially when talking to some scriptable application. See "Repeat With... In" in Chapter 19.

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.