Detecting Mac OS X version based on the User Agent stringEdit

In the past I've always offered a single version of my software products that runs on as many versions of Mac OS X as possible. This brings with it a certain simplicity (users don't have to care about which version to download and install) but it comes at a cost (tying your application to older versions of the operating system can make it difficult or even impossible to use newer APIs).

So with the release of Leopard I am finally going to branch and offer multiple versions of my products, with each branch being tied to a particular minimum version of Mac OS X.

To minimize the complexity for customers I want my download page to make a best guess at what operating system they are running and offer the appropriate download as the top choice. You'll notice this kind of customization if you try to download QuickTime or iTunes from Apple (which tries to offer you the appropriate download for your platform), or Firefox from Mozilla (which additionally tries to offer you the appropriate language variant).

WebKit based browsers

It turns out that browser and operating system detection based on user agent strings is a bit of a minefield but thanks to this handy page maintained by Apple determining visitor OS version is relatively straightforward for WebKit-based browsers.

In summary:

  • Jaguar corresponds to Safari versions 1.0 through 1.0.3, WebKit versions 85.7 through 85.8.5.
  • Panther corresponds to Safari versions 1.1 through 1.3.2, WebKit versions 100 through 312.8.1.
  • Tiger corresponds to Safari versions 2.0 through 2.0.4, WebKit versions 412 through 419.
  • Leopard numbers are not yet available (as of March 2007).

So checking the WebKit version number in the user agent string will provide a reliable way of determining the visitor OS version for people running Safari and may also work for other browsers that use WebKit such as OmniWeb.

Needless to say these user agent strings should only ever be taken as advisory, not definitive, and you should always offer your users alternative choices in the event that the auto-detected default turns out to be something other than what they want.

Gecko-based browsers

After the WebKit based browsers Firefox is probably the most popular. It's native sibling, Camino, is also powered by the Gecko rendering engine and has a sizeable minority following. As far as I know Firefox runs on any version of Mac OS X from Jaguar and up so there is no easy way to detect operating system based solely on the version number, although if the user agent string indicates an Intel processor then we know that the visitor is running at least Tiger.

Internet Explorer

Not updated in years this browser is now so old that it's probably not worth considering.

Opera

Quite popular on other platforms, Opera for Mac OS X is much less important, numerically speaking. For the time being I won't be making any effort to auto-detect the visitor's operating system for users running Opera.

iCab

Another minority browser probably not worth supporting.

Resources