Panther/Tiger scripts

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"
	display dialog "Tiger"
end if

Model: Mac G5 OS 10.3.9
AppleScript: 1.9.3
Operating System: Mac OS X (10.3.9)


this may be a little hack but…

tell application "Finder" to set osVersion to version

It does report 10.3.2 on my Panther machine (though I’m running 10.3.9 ?!?) and 10.4 on a Tiger machine. Not perfect but generally accurate.

Jim Neumann


This will give you the Darwin kernel version:

set darwinVersion to do shell script "uname -r"

And this page lists the Darwin version for each revision of OS X:

hi matt,

here’s a good way to do it:

set normalCommand to "/usr/bin/sw_vers"

set myOs to (do shell script normalCommand)

display dialog word 6 of myOs

the only thing i don’t know is if the ‘sw_vers’ command works the same way in 10.3. i only have 10.4 to test.


nice find!

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

set osVersion to text 1 thru 4 of myOs

hi guyen,

thanks. obviously i did not read the man page too closely. if only i could write an AppleScript to get me more coffee!

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
end version_to_hex

--> 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.)

Wow. These are all great ideas. Thanks for the input.