Chapter 13. Datatypes

A datatype is a classification of a value; every value is of one datatype or another. This is what AppleScript calls a class (see Chapter 10). For example, string is a datatype, integer is a datatype, and so forth. AppleScript provides a number of native datatypes; this chapter describes them.

Scriptable applications can extend the language by providing additional datatypes. For example, the Finder implements a folder datatype (or class). But such additional datatypes are confined to the application that defines them; a value returned by a scriptable application must be either a reference to an object belonging to that application, or one of AppleScript’s native datatypes.

Some values can be mutated from one datatype to another. Such a mutation is called coercion . To put it more strictly: for some pairs of datatype, call them datatype 1 and datatype 2, it is the case that at least some values of datatype 1 can be coerced to a value of datatype 2. For example, the string "1" can be coerced to a number; when that happens, you get the number 1. What coercions are possible, and how they are performed, is explained in Chapter 14 and Chapter 15.

Boolean

A boolean is a datatype consisting of exactly two possible values, true and false.

class of true -- boolean
class of (1 < 2) -- boolean

The main use for a boolean is as a condition in a control statement, such as a repeat while block (Chapter 12). For the operators that generate and combine booleans, see Chapter ...

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.