Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the running Mac OS X version programmatically?

I have a program which needs to behave slightly differently on Tiger than on Leopard. Does anybody know of a system call which will allow me to accurately determine which version of Mac OS X I am running. I have found a number of macro definitions to determine the OS of the build machine, but nothing really good to determine the OS of the running machine.

Thanks, Joe

like image 515
Joe Corkery Avatar asked Oct 01 '08 14:10

Joe Corkery


People also ask

How do I know what version of OSX I am running?

From the Apple menu  in the corner of your screen, choose About This Mac. You should see the macOS name, such as macOS Monterey or macOS Big Sur, followed by its version number. If you need to know the build number as well, click the version number to see it.

How do I know what version of Darwin is on my Mac?

macOS 11.3, iOS 14.5, iPadOS 14.5, watchOS 7.4 and tvOS 14.5. The command uname -r in Terminal will show the Darwin version number ("20.3. 0"), and the command uname -v will show the XNU build version string, which includes the Darwin version number.


1 Answers

See this article here

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

Edit: For Mac OSX 10.8 and above, don't use Gestalt() anymore. See this answer for more details: How do I determine the OS version at runtime in OS X or iOS (without using Gestalt)?

like image 100
Nik Reiman Avatar answered Oct 02 '22 20:10

Nik Reiman