How to determine the software version of Mac OS X?

I have a program that should behave a little differently on Tiger than on Leopard. Does anyone know a system call that will let me pinpoint which version of Mac OS X I'm running. I found several macro definitions to determine the build OS, but nothing really bad to determine the OS of the current machine.

Thanks Joe

+14
cocoa carbon macos
Oct 01 '08 at 14:06
source share
8 answers

See this article here.

But, if you use carbon, use the Gestalt () call, and if you use cocoa, there is a constant called NSAppKitVersionNumber, which you can simply check.

Edit: For Mac OSX 10.8 and later, do not use Gestalt (). See this answer for more information: How to determine the OS version at run time in OS X or iOS (without using Gestalt)?

+15
01 Oct '08 at 14:13
source share

Could you just check the availability? For example:

if (NSClassFromString(@"NSKeyedArchiver") != Nil) 

or

 if ([arrayController respondsToSelector: @selector(selectedIndexes)]) 

then you know that the operating system does what you need, but not that the Apple product marketing team gave it a certain number; -)

+12
01 Oct '08 at 21:52
source share

API through Gestalt Manager.

See " Determining the OS Version " on the CocoaDev website.

+8
01 Oct '08 at 14:15
source share

In terminal:

 system_profiler SPSoftwareDataType 

gives:

 Software: System Software Overview: System Version: Mac OS X 10.5.5 (9F33) Kernel Version: Darwin 9.5.0 Boot Volume: Main Boot Mode: Normal Computer Name: phoenix User Name: Douglas F Shearer (dougal) Time since boot: 2 days 16:55 

Or:

 sw_vers 

It gives:

 ProductName: Mac OS X ProductVersion: 10.5.5 BuildVersion: 9F33 
+6
01 Oct '08 at 14:10
source share

Is the OS version really needed? Perhaps a more suitable thing to check, for example, the presence or version number of a particular structure.

+2
01 Oct '08 at 15:19
source share

You can use Gestalt in your program. Here is the code that I use for my program to get the OS version.

 long version = 0; OSStatus rc0 = Gestalt(gestaltSystemVersion, &version); if((rc0 == 0) && (version >= 0x1039)) { // will work with version 10.3.9 // works best with version 10.4.9 return; // version is good } if(rc0) { printf("gestalt rc=%i\n", (int)rc0); } else { printf("gestalt version=%08x\n", version); } 
+1
Jul 28 '09 at 8:07
source share

respondsToSelector: Almost certainly better than you maintain a table of what these releases do and don't implement.

Be lazy. Let the runtime tell you if it can do something or not, and when you need to, go back to the older methods. Your code will be much less fragile because you do not need to maintain your own global data, which the rest of your code should check with.

0
Nov 21 '08 at 21:29
source share

Run this on the command line:

 system_profiler SPSoftwareDataType | grep Mac 
0
Mar 16 '09 at 20:07
source share



All Articles