If you've ever studied a Finder dictionary, you may have come across a command called computer. Its purpose is to provide (&/or test for) particular attributes when fed with four character codes, called Gestalt Selectors. In keeping with the current Finder is just another app (as opposed to the old Finder is the computer) ideology, this command is now called system attribute and has been extended with some shell environment variables and passed off to the Standard Additions osax in OS X.
I originally conceived of this page as being another table made from the codes I got out of Gestalt.h, but they're far less accessible than those from the Folders.h header. Many of the values returned require interpretation - often a decimal to hexadecimal conversion - and some of them return a boolean if the optional has parameter is specified:
system attribute "evnt" -- Apple Events attributes
--> 23 -- no idea what this means
system attribute "evnt" has 1 -- gestaltScriptingSupport
This is allows all sorts of useful things, such as determining whether the processor has AltiVec:
if (system attribute "cput" has 273) then -- hex 0x0111, means we have AltiVec
display dialog "Dude - you're running a genuine Velocipede Engine!" with icon 1
display dialog "Reality Distortion Field Error:" & return & return & "This example requires a Velocipede Engine." with icon 0
A few of the more readily useful and understandable selectors I've come across. The first example shows a fully compatible (all systems, including OS X) method for calling gestalt codes, which can be used for all of them.
Return the installed memory. This calls convertByteSize (which can be found here) to return a human readable figure.
tell application "Finder" to set ramBytes to computer "ram " -- should work on all systems back to System 7.5, though it will compile differently under OS X
set ramStr to convertByteSize on ramBytes
--> "704.00 MB"
set ramStr to convertByteSize on (system attribute "ram ") -- for AS 1.8 or later only, use the above syntax for earlier systems
To get the logical memory - the adjustable Virtual Memory on classic MacOS, or X's own system, substitute "lram" for "ram " in the above examples.
Get the processor and bus clock speeds, in megahertz.
set prcClckMHz to round ((system attribute "pclk") / 1.0E+6)
set busClckMHz to round ((system attribute "bclk") / 1.0E+6)
return "" & prcClckMHz & "/" & busClckMHz & " MHz"
--> "400/100 MHz"
Whilst there are many ways to do this, some recent versions of the System and Finder have been less than helpful. As far as I know, this should return an accurate number on any system back to 7.5 and allows for a numeric comparison, which can be handy.
This example shows the backward compatible syntax, no Finder tell is required under OS X. It requires a decimal to hex conversion to get an understandable number, though this is not necessary if the decimal number of the minimum system requirement is known.
tell application "Finder" to set sysVers to computer "sysv"
--> 4128 -- hex 0x1020, OS 10.2
Here are some of the decimal values returned for varying OS versions:
System 7.5 - 1872; 7.5.3 - 1875; 7.5.5 - 1877
System 7.6 - 1888; 7.6.1 - 1889
MacOS 8.0 - 2048
MacOS 8.1 - 2064
MacOS 8.5 - 2128; 8.5.1 - 2129
MacOS 8.6 - 2144
MacOS 9.0 - 2304; 9.0.4 - 2308
MacOS 9.1 - 2320
MacOS 9.2 - 2336; 9.2.2 - 2338
OS X 10.0 - 4096
OS X 10.1 - 4112; 10.1.2 - 4114; 10.1.5 - 4117
OS X 10.2 - 4128; 10.2.2 - 4130; 10.2.3 - 4131; 10.2.5 - 4133; 10.2.6 - 4134; 10.2.8 - 4136
OS X 10.3 - 4144; 10.3.1 - 4145; 10.3.2 - 4146; 10.3.3 - 4147; 10.3.4 - 4148; 10.3.5 - 4149; 10.3.6 - 4150; 10.3.7 - 4151; 10.3.8 - 4152; 10.3.9 - 4153
OS X 10.4 - 4160
One of the ways this could be used is to check for a value equal to or greater than the requirement and taking appropriate action:
tell application "Finder" to set runningX to ((computer "sysv") ≥ 4096)
--> true -- if running under OS X
Any time a decision needs to be based on this, the boolean is tested:
if runningX then
-- take some action
-- take some other action
This handler uses a backward compatible method for determining system version.
Getting the OS version is useful but getting the AppleScript version is the only certain way of determining whether or not specific functionality exists. Classic MacOS allowed for a certain amount of mixing of OS and AS versions, so a particular OS version doesn't guarantee much. Even though this has changed to some extent in OS X, it is still safer to check the AS version directly rather than making an assumption.
AppleScript knows its own version and it is possible to get this directly by simply typing version into a script editor and running that. In a functional script we might use something like:
set asVers to AppleScript's version
--> "1.9.3" -- with a standard 10.3.3 install
The trouble with that result is firstly that it's a string not immediately coercible to a number and secondly that certain versions of AS were localised and therefore start with a letter. From memory, AppleScript used to return something like "Z1.6" for Australian versions. These two issues make it difficult to use AppleScript's version for numeric comparisons.
The selector "ascv" is similar to "sysv" in that it returns a decimal representation of a hex number, so a decimal to hex conversion is also required. Calling "ascv" also returns extra information - the earliest version of AS with which the current version will work.
This is what I get on my machine running OS 10.3.3
system attribute "ascv"
Using Smile's Decimal to Hexa script, I get this - " 0110 0193" - which tells me that I'm running AS 1.9.3 and that it is compatible with AS versions back to 1.1.0.
Given that all versions of AS up until this point are compatible back to AS 1.1, a simple numeric comparison is possible, using the number returned by the system attribute command. Here are some of the decimal values returned under various versions of AppleScript:
AS 1.1 (OS 7.5.x) - 17826064; AS 1.1.2 (OS 8.1) - 17826066
AS 1.3.4 (OS 8.5.1) - 17826100; AS 1.3.7 (OS 8.6) - 17826103
AS 1.4 (OS 9.0?) - 17826112; AS 1.4.3 (OS 9.0.4) - 17826115
AS 1.5.5 (OS 9.1) - 17826133
AS 1.6 (OS 9.2.1/OS 10.0) - 17826144 - this can be very hard to test for, see the notes below
AS 1.7 (OS 9.2.2/OS 10.1) - 17826160 - this version of AS is bad news for OS 9.x, avoid it if possible
AS 1.8.2 (OS 10.1.2/OS 9.x) - 17826178; AS 1.8.3 (for OS 10.1.x/OS 9.x) - 17826179
AS 1.9 (OS 10.3) - 17826192; AS 1.9.2 (OS10.3.1) - 17826194; AS 1.9.3 (OS10.3.3-10.3.8) - 17826195
Notes: I discovered whilst researching this that Bill Cheeseman has most if not all of this information available in this section of his excellent site. The AppleScript Sourcebook is the place for definitive information on features and bugs in various AS versions, including the convoluted method required for testing if AS 1.6 is installed.
This handler uses a backward compatible method for determining AS version.
If you're running OS X, have the Developer Tools installed in the default location and are running 10.2.x, you can click here for the Gestalt Manager documentation. Under 10.3, the file should be found here. Otherwise, try the online version on Apple's Developer site.
The FooDoo Lounge is Copyright © Richard Morton 2002-2005
|| url: http://www.foodoo.sunreal.com.au/info/gestalt.html
|| created: 16-Aug-04, 10:51 PM; updated: 26-Feb-05, 11:18 PM
|| size: 35504 bytes