Name

Unit of Measurement Classes

Allowed coercions

integer, real, and string

Syntax

set theMeters to 6000 as meters

Description

AppleScript provides six categories of classes for representing area, length, temperature, cubic volume, liquid volume, and weight measurements. These data types are very handy for converting measurements within the categories:

Area value types

square feet

square kilometers

square kilometres

square meters

square metres

square miles

square yards

Length value types

centimeters

centimetres

feet

inches

kilometres

kilometers

metres

meters

miles

yards

Temperature value types

degrees Celsius

degrees Fahrenheit

degrees Kelvin

Cubic volume value types

cubic centimeters

cubic centimetres

cubic feet

cubic inches

cubic metres

cubic meters

cubic yards

Liquid volume value types

gallons

litres

liters

quarts

Weight value types

grams

kilograms

ounces

pounds

Tip

degrees Kelvin and quarts began with AppleScript Version 1.3.7, along with the coercion of miles to other length-measurement types.

Examples

You can only coerce back and forth between measurement classes within the same category. The return values for these classes are the name of the data type followed by a space and its value. The return value of:

set theMeters to 6000 as meters

is “meters 6000.0” and its class is meters. The following code illustrates what is and is not permitted in terms of using these classes. The end of the code example shows the results from Script Editor’s Event Log ...

Get AppleScript in a Nutshell 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.