Example 14-1 finds
out which OS the computer is running by using a property of the
Finder called, aptly enough, product version
. The
script first saves product
version
, a string
, to a
variable called myOS
. You need to enclose this
variable assignment in a tell
block that targets
the Finder, because product version
is a property
of the Finder. Otherwise, AppleScript would not know which product
version you were referring to. The script then tests the OS version
to determine if it is less than 8.5 with the following code
statement:
characters 1 thru 3 of myOS
This returns a list
like
{"9”,
“.”,"0"}.
This list
is converted to text with the
as
text
coercion statement, so
now it looks like “9.0.” The entire
statement is:
(characters 1 thru 3 of myOS as text)
This string
(“9.0”) is then coerced or
converted to a real
number (9.0), which is a
number with a decimal point and fractional part (unlike an
integer
, which is a whole number), so we can
compare this number with 8.5. This coercion is not strictly
necessary, but I like to make explicit conversions so I always know
which data type I am working with.
If the myOS
value (e.g., 9.0) is less than 8.5, a
dialog displays telling the user the script will quit. This function
derives from a script that I wrote depended on Mac OS 8.5 or greater
to run properly.
getOS( ) (* function definition *) on getOS( ) tell application "Finder" set myOS to (product version) if ((characters 1 thru 3 of myOS as text) as real) < 8.5 then display dialog "You cannot run this applet unless the computer" &¬ " has Mac OS 8.5. or later." & return & return &¬ giving up after 45 return -- quit applet else display dialog "Good, your OS is: " & myOS end if end tell end getOS