Getting Ready to Script
Before you begin to script applications, you’ll need to have at least a passing command of AppleScript or some other programming background that will let you follow the examples provided in this chapter. You aren’t required to have mastered the language before working through these projects, but it helps to have at least a basic familiarity.
AppleScript is a language that was designed for use by a wide audience without needing a strong programming background. With its “English-like” syntax and simple data structures, it’s a very approachable programming language. As Example 9-3 shows, a snippet of AppleScript code remains very readable even when dealing with mathematics and string concatenation. This example converts a number from Fahrenheit to Celsius, then speaks the results out loud. The lines starting with a double dash are comments.
Example 9-3. AppleScript’s readable English-like syntax
-- Initial temperature in Farenheit set ftemp to 100 --Offset by–32 and scale by 5/9 set ctemp to (ftemp - 32) * (5 / 9) --Round to two decimal places set ctemp to setPrecision(ctemp, 2) --Convert to strings set ftemp to ftemp as string set ctemp to ctemp as string set spoken to ftemp & " degrees Fahrenheit equals " & ctemp & " degrees ...