1.5 Checking Your AppleScript VersionThis introduction would not be complete without mentioning how important it is to check which version of AppleScript is running on the machine executing your scripts. This is particularly true if your script is used on computers that might not be running Mac OS 9 or later. New versions of AppleScript are generally released along with the latest generation of the operating system. Mac OS 9 contains AppleScript Version 1.4 (an updated version of AppleScript, Version 1.4.3, also runs on OS 9). In the Spring of 2001, Mac OS 9.1 and Mac OS X used AppleScript 1.6. There is an extremely simple way to find out which version of AppleScript is installed on the machine where the script is running. Checking the value of the version property in Script Editor will return the version number, as in 1.4 in Mac OS 9 or 1.3.4 in Mac OS 8.5. If you do not understand certain aspects of this script, Part II of the book is a detailed AppleScript language reference. Your script can check the version property with code such as that shown in Example 1-6. Example 1-6. Checking the AppleScript Version Numberset ASversion to version as string -- initialize ASversion to a string set ASversion to (characters 1 thru 3 of ASversion as string) as real (* coerce ASversion to a real number like 1.4 *) if ASversion is greater than or equal to 1.4 then (* test whether the version value is 1.4 *) display dialog "Good, you're running at least AppleScript 1.4" (* give the user some feedback with a dialog box *) else display dialog "You're running AppleScript " & ASversion end if Example 1-6 first gets the AppleScript version property as a string value (e.g., "1.4") and stores it in an ASversion variable. The first three characters of this variable (such as 1.3 if the version was 1.3.4) are then coerced to a real type, as in 1.3. We had to take just the first three characters of the string because a string with two decimal points in it, as in 1.3.7, cannot be coerced to a real value (since a string with two dots in it is an invalid representation of a number). Chapter 3 discusses the real data type. This numerical value is then checked to see if the user is running at least AppleScript 1.4. The script uses the display dialog scripting addition to display information to the user about the found version value. You can also check the version property of the Finder, and other applications that have this property, by first targeting the application in a tell statement, as in Example 1-7. Example 1-7. Displaying the Finder Version Numbertell application "Finder" set fVersion to version as string display dialog "You're running Finder version " & fVersion end tell |