Re: how to get OS version with Shell script?
Re: how to get OS version with Shell script?
- Subject: Re: how to get OS version with Shell script?
- From: kai <email@hidden>
- Date: Mon, 15 Jan 2007 23:53:38 +0000
On 11 Jan 2007, at 20:24, Wallace, William wrote:
From: "Mark J. Reed" <email@hidden>
Date: Thu, 11 Jan 2007 10:51:38 -0500
To: William Knight <email@hidden>
Cc: Horky Chen <email@hidden>, <applescript-
email@hidden>
Subject: Re: how to get OS version with Shell script?
If you really want to use the shell, it's
set osx_version to (do shell script "sw_vers -productVersion")
Now are there any restrictions or caveats to either of these
methods? I
mean, will one or both of these methods fail in certain versions of
OSX. I
seem to recall that 'do shell script' was not available in the very
first
incarnations of OSX. Is that true or did I dream it? ;-}
I'm not personally aware of any such qualification for sw_vers, Bill.
However, while there could be a specific reason for requiring a shell
in this case, it may be worth noting that the Standard Additions'
"system info" command (suggested earlier) was introduced in
AppleScript 1.10 (Mac OS X 10.4). So if anyone needs to check for pre-
Tiger versions, this may not be the best choice.
Another non-shell alternative (also suggested previously) is to use
<system attribute "sysv">. The decimal-coded hex value is returned
considerably faster than most alternative methods (it's about 50
times faster than system info and 140 times faster than sw_vers,
here). In addition, when wrapped in a Finder tell statement, it even
works pre-OS X (where the raw code for 'system attribute', «event
fndrgstl», decompiles as 'computer').
The most common need for such a value is to determine whether or not
software matches or exceeds a given version threshold. So, while a
conversion routine may be required to derive a more human-
understandable value, it isn't usually essential to the script
function. If the decimal-coded hex number of the target system is
known, it's generally quicker and cleaner to make a direct comparison
with that, instead. For example:
-----------------
tell application "Finder" to set Mac_OS_X to (system attribute
"sysv") ≥ 4096
-----------------
Or:
-----------------
set pre_Tiger to (system attribute "sysv") < 4160
-----------------
To determine the equivalent "sysv" value, I suppose a rough and ready
conversion might go something like:
-----------------
on decimal_value for v
set text item delimiters to "."
set l to v's text items
set text item delimiters to {""}
set n to 0
tell l to repeat with i in beginning & ¬
items 1 thru 2 of (rest & {0, 0})
set n to n * 16 + i
end repeat
end decimal_value
set required_version to "10.4" (* or whatever *)
decimal_value for required_version --> 4160
-----------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden