I want to get the OS X system version, such as: 10.5.4, 10.4.8, etc. I want to get it in my app, how do I do this? Thanks!
-
@JakePetroules how this one could be a duplicate if it was asked 7 years ago and pseudo original - 4 years ago! Look at dates please. – Mykhailo Lysenko Aug 16 '16 at 17:35
-
Because the other question contains the correct answer as the accepted one. This one contains all wrong or outdated answers except one which is way at the bottom. Stack Overflow is a wiki for people to find answers, not a historical log of questions and answers. – Jake Petroules Aug 16 '16 at 17:47
8 Answers
You can read the property list at "/System/Library/CoreServices/SystemVersion.plist and extract the "ProductVersion" key, this is how the OS X installer application does it. Here's an example:
NSString *versionString;
NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
versionString = [sv objectForKey:@"ProductVersion"];
Alternatively, the command swvers -productVersion
will do the same.

- 378
- 1
- 2
-
That works, but it incurs disk I/O and is unnecessary. Gestalt is a much better (and faster) alternative. – Quinn Taylor Sep 16 '09 at 16:47
-
2But deprecated since 10.8 and it seems that this is the best way currently available. See this question: http://stackoverflow.com/questions/11072804/mac-os-x-10-8-replacement-for-gestalt-for-testing-os-version-at-runtime – hobotron Oct 02 '12 at 10:11
-
-
2@QuinnTaylor Gestalt just reads SystemVersion.plist, so it *does* incur disk I/O. Try changing the contents of that file and you'll notice it prints different results. – Jake Petroules Feb 26 '14 at 22:36
-
Looking at /System/Library/CoreServices/SystemVersion.plist is useful if, say, you have cloned to an external drive but you don’t know which version. – user535673 Mar 31 '15 at 17:21
NSString *osver()
{
SInt32 versionMajor=0, versionMinor=0, versionBugFix=0;
Gestalt(gestaltSystemVersionMajor, &versionMajor);
Gestalt(gestaltSystemVersionMinor, &versionMinor);
Gestalt(gestaltSystemVersionBugFix, &versionBugFix);
return [NSString stringWithFormat:@"%d.%d.%d", versionMajor, versionMinor, versionBugFix];
}

- 15,547
- 6
- 61
- 83
You can use Gestalt:
SInt32 version = 0;
Gestalt( gestaltSystemVersion, &version );
BOOL leopard = ( version >= 0x1050 );
if ( leopard )
{
//draw it this way
}
else
{
//draw it that way
}
Keep in mind if you're checking if a method is available or not, it's better to test that directly using respondsToSelector:.

- 40,399
- 3
- 75
- 82
-
14Note that gestaltSystemVersion is discouraged since 10.4 in favor of gestaltSystemVersionMajor, gestaltSystemVersionMinor, and gestaltSystemVersionBugFix, due to the 1-digit limit. 10.4.10 and .11, for example, are impossible to detect using your code. – smorgan May 20 '09 at 15:12
-
5As Gestalt is deprecated in 10.8, is there an alternative way that works from 10.6 - 10.8? – adib Jul 27 '12 at 17:14
-
4This answer is now straight up wrong, since gestaltSystemVersion cannot represent 10.10. – Jens Ayton Jun 07 '14 at 15:31
-[NSProcessInfo operatingSystemVersionString]
is human readable and localized. Appropriate for displaying to user or using in bug emails and such, but not appropriate for parsing.

- 9,383
- 7
- 36
- 58
-
+1: Very nice. I suggested a slight edit of mentioning the class method `+processInfo` for getting an instance to call `-operatingSystemVersionString` on. – ArtOfWarfare May 05 '13 at 18:45
-
is it possible to call [NSProcessInfo operatingSystemVersionString] from C++ code? – Vlad Feb 12 '15 at 14:29
-
No. You'd need to create a wrapper method around it in order to call it from C++ and you'll have to add some Objective-C to your program in order to do that. You could make that file Objective-C++, you could use Gestalt, you could use system() to call swvers -productVersion from the command line, or you could read it from the file system (as mentioned elsewhere on this page). It just depends on your situation and what you are trying to do. – brant Mar 11 '16 at 17:18
Again, you can use Gestalt. Look at the documentation for more information; specifically, you'll want to pass the gestaltSystemVersionMajor
, gestaltSystemVersionMinor
, and gestaltSystemVersionBugFix
constants in the "System Version Constants" portion of the Gestalt Manager Reference documentation

- 48,806
- 11
- 116
- 129
After 10_10, 8_0 were presented the better & simplest way would be
[NSProcessInfo processInfo].operatingSystemVersion
which will return
NSOperatingSystemVersion
struct
with all 3 numbers.

- 164
- 8
use this method it will return Mac OS X version
+(SInt32) OSVersion;
{
SInt32 osxMinorVersion;
Gestalt(gestaltSystemVersionMinor, &osxMinorVersion);
return osxMinorVersion;
}

- 990
- 8
- 19
There's also a Cocoa wrapper around the Gestalt calls others have mentioned in the Google Toolbox for Mac: http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMSystemVersion.h

- 20,228
- 3
- 47
- 55
-
Meh, seems like more trouble than it's worth for a simple check. Maybe if I were already using GTM, but it's simpler to just check `gestaltSystemVersionMinor`. – Quinn Taylor Sep 16 '09 at 16:46