Basics of AppleScript

Coercion

Script [7.3.1]:

set myAge to display dialog "What is your age?" default answer ""
set studentAge to text returned of myAge as number

Explanation: Variable myAge will store details of dialog. The dialog will ask the user for his/her age. studentAge will contain the value entered by user. But here’s the catch. I have asked AppleScript to convert the text to number. As I don’t want age to be a String.

Figure 7.3.1

Figure 7.3.1-2

Figure 7.3.1 Without Coercion

Figure 7.3.1-3

Figure 7.3.1-2 With Coercion