Using Gestalts in RB
By Dan Vanderkam
Note: 2.0.1a2 or later is needed to use this article.

  No, it's not just a funny word. Gestalts are a way that a program can ask for certain info about a computer from the system. For example, you could get the version of QuickTime, or the system bus's clock speed using Gestalts. They're quite useful.

  To access Gestalts, RB uses a simple method: System.Gestalt. This function returns a boolean (indicating whether the gestalt exists or not), and it takes two parameters: the four letter code of the gestalt, and an integer that will contain the info.

  For example, to get the clock speed of the computer, we might use this code:

Dim speed as integer
if System.Gestalt("pclk", speed) then
  msgbox "Your system runs at "+str(speed)+" Hertz."
else
  msgbox "Something is seriously bizarre with your computer."
End if

  When I run this code, RB displays the message "Your system runs at 2.40000000e+8 Hertz." If you multiply out that number, you'll find that it's 240 million. 240 million Hertz is 240Mhz, which is what my computer runs at.

  However, the numbers that are given by System.Gestalt aren't always so nice. Many Gestalts return a version number. For example, if we replaced System.Gestalt("pclk", speed) with System.Gestalt("qtim", speed), we'd be told that the QuickTime version is 67133473. Oddly enough, this number represents Quicktime 4.0.0. However, we we convert this number into hexadecimal, things become clearer. In hex, this number is 4006021. So, the first number of the version in Hex is the major release. The second is the minor release, and the third is the maintenance release number. So, this routine should tell us the version of QuickTime in ordinary english:

Dim Version as integer, vers as string
dim major, minor, maint as string
if System.Gestalt("qtim",version) then
vers=hex(version)
major=mid(vers, 1, 1)
  minor=mid(vers, 2, 1)
  maint=mid(vers, 3, 1)
  MsgBox "QuickTime version is "+major+"."+minor+"."+maint+"."
else
  MsgBox "QuickTime isn't installed."
end if

  That system for using versions isn't true only for QuickTime. It also works for almost anything else that returns a version.

  Now that you know how to use a Gestalt in your program, here's a list of codes you might want to try:

Code Description
qtim Returns the QuickTime version
ag_v Returns the version of AppleGuide (if it's present)
appr Appearance manager. Returns 1 if it's there, 0 if it's not.
apvr Returns Appearance Manager version.
ascr/ascv AppleScript present/version number
cash The amount of RAM given to the disk cache (in bytes)
cmnu The Gestalt function returns true if contextual menus are installed, false if they're not.
cpkr Returns the color picker version.
doub Returns the version of WorldScript (if installed)
dkpx Returns the version of the Desktop Pictures control panel (if installed)
micn Returns the computer's icon family ID. All icons are generic after System 7.5
nvsv Gestalt returns true if NavServices are present, false if they aren't
otvr Returns the Open Transport version.
thds Gestalt returns true if the Thread Manager is present, false if it isn't.

usb Gestalt returns true if USB abilities are available, false if they aren't.
rom Returns the amount of ROM in bytes.
pclk Returns the processor speed in Hertz (1,000,000 Hz=1Mhz)
mach Returns the machine type (ie, PowerBook 3400c). Look this up for machine types.
ram /lram The amount of RAM/Logical RAM (in bytes)
fpu Returns 0 if no FPU, higher than that if there is. Be sure to write 'fpu '
bclk Returns the bus speed in Hertz (1,000,000 Hz=1 Mhz)
cput Returns the CPU type as a special number:

• 68000 = 0 • 68040 = 4 • PPC 603e = 262
• 68010 = 1 • PPC 601 = 257 • PPC 603ev = 263
• 68020 = 2 • PPC 603 = 259 • PPC 604e = 265
• 68030 = 3 • PPC 604 = 260 • PPC 604ev = 266
    • PPC 750 (G3) = 264

  For a much more complete list of codes, check out the Gestalt Selectors List 4.3.2 Overview page, which has a comprehensive list of all the known four letter gestalt codes. The table I've included here is just a small helping of what's on that page. Enjoy!