I have a couple of scripts in Panther that need a minor tweak to work in Tiger (which our art department is switching to in the near future). We had an idea that instead of creating a second set of Tiger-only scripts, that we make “universal” scripts that would check at the beginning of running to see what OS the computer is running and then branch from there to use the correct code.
So far, the only way I can see to do this is the “version” command. It tells you what version of AppleScript you are running. Is there a command to get the OS version? That seem like it would be less prone to problems than:
if (version as string) is "1.9.3" then
display dialog "Panther"
else
display dialog "Tiger"
end if
Model: Mac G5 OS 10.3.9
AppleScript: 1.9.3
Operating System: Mac OS X (10.3.9)
I look at the man page. It refers to 10.3 and even 10.2 when explaning examples. So it should work. Also found you add “-productVersion” just the OS version:
set normalCommand to "/usr/bin/sw_vers -productVersion"
set myOs to (do shell script normalCommand)
display dialog myOs
Then you can remove minor version and just get 10.3 or 10.4 with
For this sort of thing, I usually use the following (which, if in a Finder tell statement, should even work pre-OS X):
set OS_Tiger to (system attribute "sysv") ≥ 4160
The value 4160 is a hexadecimal representation of 10.4.0 - which could be tested thus:
on version_to_hex(v)
set h to 0
repeat with n from 3 to 0 by -1
tell 10 ^ n to set {h, v} to {h + v div it * (16 ^ n), v mod it}
end repeat
h
end version_to_hex
version_to_hex(1040)
--> 4160
(I don’t generally use the conversion in a finished script. It’s quicker to use the raw hex value for comparisons - which, here, is about 25 times faster than an equivalent shell script.)