Re: AS and Gestalt
Re: AS and Gestalt
- Subject: Re: AS and Gestalt
- From: Chris Nebel <email@hidden>
- Date: Fri, 22 Dec 2000 14:45:01 -0800
- Organization: Apple Computer, Inc.
Carl West wrote:
>
Christopher Nebel wrote:
>
>...
>
> Alternatively, you can use the Finder's "computer" verb, but you have to
>
> know the Gestalt codes and how to interpret the results.
>
>
I'm short some clues here.
>
>
The phrase 'use the Finder's "computer" verb' isn't getting me very far,
>
The only thing I tried that worked was:
>
>
tell app "Finder"
>
set foo to computer name
>
end tell
>
>
but how I get to Gestalt from here is a mystery, getting to the
>
appropriate selector is a mystery, and interpreting the results is a mystery.
>
>
I seem to be missing some underlying concepts for dealing with
>
AppleScript and don't know where to find them.
>
>
Is there some way I can ask the Finder's "computer" verb how to use it?
>
ask it what properties it has?
Another shining example of dictionary design strikes again. The Finder's
"computer" verb is a very, very thin veneer on the native Gestalt API. In order
to use it, you have to know the Gestalt selector codes and what all the results
mean. This information is unfortunately not available via AppleScript itself --
you have to read the Gestalt documentation. (By the way, despite appearances,
"computer name" has no relation whatsoever to "computer". It's actually a verb
defined in the FileSharing Commands scripting addition.)
So, Gestalt documentation: for starters, read
<
http://developer.apple.com/techpubs/mac/OSUtilities/OSUtilities-13.html> for a
list of constants and what the responses are. Unfortunately, that page has two
problems: first, it only gives you the C/Pascal constant names, not the
four-character codes you need for "computer", and second, it only lists the
older selectors.
You can cure the first problem by reading
<
http://developer.apple.com/techpubs/mac/OSUtilities/OSUtilities-27.html> -- it
has the same information as the first, but is less readable. To cure the
second, you'll need a copy of Gestalt.h. It's included with the Carbon SDK
<
ftp://ftp.apple.com/developer/Development_Kits/CarbonLib_1.0.4_SDK.sit.hqx>,
but that's about a 7MB download, so I've put a copy of Gestalt.h on my iDisk
<
http://hompage.mac.com/c.nebel> -- it's a relatively svelte 88K.
Now that you've got all that, how about an example? Say you want to know how
fast the Mac is you're running on. Browsing through Gestalt.h, we find that
there's a selector gestaltProcClkSpeed = FOUR_CHAR_CODE('pclk'). We use the
four-character code as a string, so in AppleScript, that's:
tell application "Finder"
computer "pclk"
end
On my machine, it responds with 500000000, or 500MHz. (Woohoo!) I hope that
clears things up a bit.
--Chris Nebel
AppleScript Engineering