O'Reilly logo

AppleScript® Programming for the Absolute Beginner by Jerry Lee Ford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data Coercion

AppleScript automatically recognizes a value’s data type based on how you use it. For instance, any value enclosed inside a pair of matching double quotation marks is treated by AppleScript as a string type.

set x to "Alexander Ford"

On the other hand, assigning a numeric value as shown next results in a numeric assignment. Note that numeric values are not enclosed within double quotation marks.

set x to 10

If, however, you enclose a number within double quotation marks as shown next, AppleScript will assign the value a string data type.

set x to "10"

AppleScript also lets you make an explicit data type assignment using an as clause, as demonstrated here:

set x to 10 as string

This is an example of explicit coercion. It is often ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required