Re: System version as number (on non-US systems)
Re: System version as number (on non-US systems)
- Subject: Re: System version as number (on non-US systems)
- From: Kai Edwards <email@hidden>
- Date: Mon, 16 Sep 2002 01:03:50 +0000
on Wed, 11 Sep 2002 21:17:17 +0200, Brennan <email@hidden> wrote:
>
I'm sure this has been up before, sorry if it's a FAQ.
>
>
On my International English MacOS9, (version of application "Finder") is
>
returning "Z1-9.1" ("Z" is the code for International English, in case people
>
didn't know this).
>
>
I also notice that 'product version' on OSX returns an empty string. (Er...)
>
This is supposed to be the OS version, as distinct from the Finder version -
>
which is splitting hairs, but I am sure people would prefer to target the OS,
>
rather than the Finder.
>
>
This makes me wonder whether we have to apply complicated heuristics to know
>
whether it's a non-US OS9 (or less) or OSX.
>
>
Here's my idea: Can I strip everything up to and including a hyphen character
>
- if one exists - and then coerce to number? Would that work with all PPC Mac
>
systems?
>
>
The code I have to do this is as follows:
>
>
tell application "Finder"
>
set vString to (version of application "Finder")
>
>
try
>
set v to vString as number
>
on error msg number n
>
>
if n is -1700 then -- can't coerce vString to number
>
>
set o to (offset of "-" in vString) + 1
>
set AppleScript's text item delimiters to ""
>
set vString to ((characters o thru end of vString) as string)
>
set v to vString as number
>
>
else
>
error number n
>
end if
>
>
end try
>
return v
>
>
end tell
>
>
>
Isn't this outrageously complicated? Surely there's a better way to do this?
>
>
On OSX, I'm getting "10.1.2" because (of course) it's an international OS, so
>
does not require a language code in the version, but does this really help?
>
Can I rely on this?
>
>
Isn't there some way of getting these values reliably as numbers? Is there
>
another reliable way of knowing whether it's OSX or an earlier Mac system?
Sorry about the late response, Brennan.
As you've already rightly observed, the first problem with this approach is
that we're starting with the version of the Finder rather - than that of the
Mac OS. These aren't necessarily the same on every system. (I won't go into
the details, since they've been discussed here previously - and anyway, it's
enough to know that's the case.)
To establish the system version, we can get the value of Gestalt selector
"sysv", which returns the system version in hexadecimal. We can then convert
this into something a bit more meaningful to us mere mortals.
Getting the selector is complicated (but only slightly) by the fact that the
required syntax has changed. However the underlying raw code, <<event
fndrgstl>>[1], has remained consistent - and so can be entered by using
either:
1) on older systems: the Finder term 'computer' [2]
2) on more recent systems: the term 'system attribute' [2]
Because the term 'computer' belonged to the Finder, it obviously needs to be
enclosed in a Finder tell block. While 'system attribute' doesn't
technically need such a block, it can still be placed in one without a
problem. This allows it to be recognised by older systems - which can
interpret the underlying code as the Finder's 'computer'.
Conversely, a script compiled on an older system using 'computer' should
also run on a more recent one (which will display the term as 'system
attribute' in an Editor).
I recently posted a short routine to get the system version as a number.
Here's a modified version that returns the version in a more 'traditional'
(X.X.X) text format:
-------------------------------------------------------------------------
try
tell application "Finder" to set {x, y} to {"", computer "sysv"}
on error number -1708 -- event not handled (no AS 1.6 commands in Classic)
set {x, y} to {"", 4096}
end try
repeat with n from 3 to 0 by -1
tell 16 ^ n to set {x, y} to {x & (y div it), y mod it}
end repeat
tell x as integer as string to set x to it's text 1 thru -3 & [NO BREAK]
"." & it's character -2 & "." & it's character -1
display dialog "Mac OS " & x & "." -- test
-------------------------------------------------------------------------
If you need to save such a script as an applet, there's another issue worth
considering. Here's the gist of it (as far as I can figure it):
When saved as a Mac OS X Applet, a script should run OK on Mac OS versions
from 9.1 onwards. Any earlier than that, and you'll probably get complaints
that 'CarbonLib' can't be found. I believe that OS 9.0 featured vs. 1.0 of
the extension, which appeared to be broken - while in OS 9.1, CarbonLib
1.1.1 is somewhat more... helpful.
Saved as a Classic Applet, the script should run on older systems. (I'm not
sure exactly how old - although I've tested it successfully back to OS 8.1.)
However, on an OS X machine, it would run in Classic Mode (unless recompiled
and resaved).
(I'm sure someone will correct me if I've got any of that wrong.) ;-) [3]
HTH.
Kai
-------------------------------------------------------------------------
[1] For anyone new to the list, the '<<' and '>>' brackets are merely a
representation of the keystrokes 'option + \' (ASCII character 199) and
'shift-option + \' (ASCII character 200) respectively. For reasons to do
with the list server, these characters may also be displayed here as '+' and
';'.
[2] I believe the watershed for what constitutes 'older' and 'more recent'
(at least in this context) may be somewhere around OS 9.2.
[3] As mentioned here before, details of much of this stuff - and a great
deal more - is available from Bill Cheeseman's excellent AppleScript
Sourcebook [4] at:
http://www.AppleScriptSourcebook.com
[4] Er... you *did* say the cheque's in the post, didn't you Bill? ;-)
--
email@hidden
email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.