views:

907

answers:

4

Hi

How can I find which version of OSX is installed on my Mac by using AppleScript? I want to install an app programatically and run different pkg files based on the version.

Thanks

+2  A: 

I'm not too familiar with AppleScript, but AFAIK you can get some info about versions from the shell with the sw_vers command.

e.g.,:

ProductName: Mac OS X ProductVersion: 10.5.6 BuildVersion: 9G55 Macintosh:~ udekel$

If you can read and parse that from appleScript, that may be a solution, though I'm sure there has to be something more elegant.

Uri
+6  A: 

I'm not on a Mac, so there may be a better way to do this, but the first approach that comes to mind is just executing a shell command to query the OS version.

http://developer.apple.com/technotes/tn2002/tn2065.html#TNTAG2

http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man1/sw_vers.1.html

Based on these references, you probably want to do something like:

set os_version to do shell script "sw_vers -productVersion"
Trevor Bramble
This works really well.
Matthew Schinckel
Why does his work well but you down vote mine? Seems a bit hypocritcal.
HappyCodeMonkey
Nevermind, I see the difference now, bah! I blame being tired :P
HappyCodeMonkey
+1  A: 

Try something along these lines:

tell application "Terminal"
activate

set theVersion to do script with command "sw_vers -productVersion"
end tell

Edit : It was pointed out that this does open the terminal, and that probably isn't the behavior you want.

HappyCodeMonkey
What if Terminal isn't running? This will launch it, scaring most users.
Matthew Schinckel
That's true, however, I was assuming the poster would modify this code to fit their needs.
HappyCodeMonkey
+2  A: 

You can get version from the Finder app as well

tell application "Finder"
    set os_version to version
end tell

display dialog os_version

On my machine this displays "10.5.8".

Anthony Cramp