Read the Mac OS X edition and version from property lists

When scripting for system administration, it’s often helpful to know what edition and version of Mac OS X is installed.

By edition, I mean whether you are using Mac OS X or Mac OS X Server — Server generally being a superset of the client operating system. The version, of course, is an indentifier such as “10.4.9” or “10.3” or “10.2.8.”

Given the version number, you can deduce the marketing name of the system software: “Tiger,” “Panther,” and “Jaguar,” respectively. Interestingly, I’m aware of no string in the system that identifies that marketing name; even “About This Mac” in the Apple menu does not display it. (However, you can find all of the names in the Mac OS X entry in Wikipedia.)

You can obtain the version information in a number of ways. From a scriptability standpoint, the quickest way to the chase is probably the sw_vers utility. The basic usage and output looks like this:

$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.4.9
BuildVersion: 8P2137

… but you can also, as of Mac OS X 10.3 or later, narrow it down to get just the string you want. (Note that you can only run sw_vers, without modification, in Jaguar and earlier.) So, if you just need the ProductVersion, ask for it:

$ sw_vers -productVersion
10.4.9

One drawback of this solution is that you can only get the version information for a running copy of Mac OS X. According to its man page, sw_vers
“prints version information about the Mac OS X or Mac OS X Server operating
system running on the local machine.” It can’t detect the version of a
non-running Mac OS X installation.

Happily, the same information is stored in two property list files in the /System directory. Therefore, you can read the version data directly from these plist files.

  • For Mac OS X workstation or client: $volume/System/Library/CoreServices/SystemVersion.plist
  • For Mac OS X Server:
    $volume/System/Library/CoreServices/ServerVersion.plist

… where $volume is the path to the target volume. The ServerVersion.plist file does not exist on workstation/client edition of Mac OS X. The mere presence of the ServerVersion.plist, therefore, indicates that you have encountered Mac OS X Server.

So, from the command line, you could enter:

$ defaults read /System/Library/CoreServices/SystemVersion 'ProductVersion'
10.4.9

… or even …

$ defaults read '/Volumes/Mac OS X Install DVD/System/Library/CoreServices/SystemVersion' 'ProductVersion'
10.4

Reading the plists comes in handy if you’re trying to detect the version of Mac OS X on a disk other than the current startup disk, where sw_vers fails. This means you can even detect the version of Mac OS X installed on Apple’s boot CDs and DVDs!

The plist method is also useful if you’re using a scripting language — such as Python, with its plistlib module (I’m sure there’s something for Perl, too … and you could also try defaults as above) — that can read them. If the files can be read directly, you don’t need to call out to a shell command, even one as simple as sw_vers or defaults, from within the scripting language. That means you won’t be spawning an additional process, and your scripts can therefore gain a slight speed increase.

Here is example defaults output from a running Mac OS X workstation (a Core 2 Duo-based MacBook Pro):

{
ProductBuildVersion = 8P2137;
ProductCopyright = "1983-2007 Apple Inc.";
ProductName = "Mac OS X";
ProductUserVisibleVersion = "10.4.9";
ProductVersion = "10.4.9";
}

And from a Tiger install DVD, originally for PowerPC:

{
ProductBuildVersion = 8A428;
ProductCopyright = "1983-2005 Apple Computer, Inc.";
ProductName = "Mac OS X";
ProductUserVisibleVersion = "10.4";
ProductVersion = "10.4";
}

To show that this is not a fluke, here’s the same result from a Panther install CD (you must use Disc 1, as it is the startup disc in the set):

{
ProductBuildVersion = 7B85;
ProductCopyright = "Apple Computer, Inc. 1983-2003";
ProductName = "Mac OS X";
ProductUserVisibleVersion = "10.3";
ProductVersion = "10.3";
}

I expect that this applies all the way back to Mac OS X 10.0 from March 24, 2001. To date, though, I’ve verified this behavior as far back as a Jaguar install CD:

{
ProductBuildVersion = 6C115;
ProductCopyright = "Apple Computer, Inc. 1983-2002";
ProductName = "Mac OS X";
ProductUserVisibleVersion = "10.2";
ProductVersion = "10.2";
}

Update: I did run the same test on a Mac OS X 10.0 install CD from 2001. The results show that you can use the property list reading method to obtain the version information for any release of Mac OS X:

{
ProductBuildVersion = 4K78;
ProductName = "Mac OS X";
ProductVersion = "10.0";
}

However, note that the ProductUserVisibleVersion and ProductCopyright keys are not in the plist of the Cheetah system.

The information above was adapted from my similar post on the MacEnterprise list.