How to know OS Version

  • Hi All,

            Is there any way to know the operating system version i.e
    either Leopard or Tiger ?

            Please let me know if you have any concern(s).

    Thanks,
    JanakiRam.
  • On Sat, 17 Nov 2007 10:56:50 +0100, JanakiRam <johnyatforums...>
    wrote:

    > Hi All,
    >
    > Is there any way to know the operating system version i.e
    > either Leopard or Tiger ?

    Gestalt will do this for you:

    long version;
    Gestalt(gestaltSystemVersion, &version);
    if (version < 0x1040)
    {
      // older than 10.4
    } else if (version < 0x1050)
    {
      // older than 10.5
    } else {
      // 10.5 or higher
    }

    Note that you will need to include the Carbon headers.
    Gestalt() is declared as
    extern OSErr Gestalt( OSType  selector, long *  response)
    in the 10.4 SDK - I believe the 2nd parameter type has changed in the 10.5
    SDK to since long changes to 64 bits in the LP64 model.

    -Stefan
    --
    "The good news is that in 1995 we will have a good operating system and
    programming language; the bad news is that they will be Unix and C++."
  • In Cocoa, you use the following code :

      NSString * systemVersionFile = @"/System/Library/CoreServices/
    SystemVersion.plist" ;
      NSData * data = [NSData dataWithContentsOfFile:systemVersionFile] ;
      NSDictionary * dict = [NSPropertyListSerialization
        propertyListFromData:data
        mutabilityOption:NSPropertyListImmutable
        format:NULL
        errorDescription:nil
      ] ;
      NSLog (@"%@", dict) ;

    The dictionary defines several keys : ProductUserVisibleVersion,
    ProductVersion, …

    -Pierre

    Le 17 nov. 07 à 10:56, JanakiRam a écrit :

    > Hi All,
    >
    > Is there any way to know the operating system version i.e
    > either Leopard or Tiger ?
    >
    > Please let me know if you have any concern(s).
    >
    > Thanks,
    > JanakiRam.
    >
  • On Nov 17, 2007, at 3:25 AM, Pierre Molinaro wrote:

    > In Cocoa, you use the following code :
    >
    > NSString * systemVersionFile = @"/System/Library/CoreServices/
    > SystemVersion.plist" ;
    > NSData * data = [NSData dataWithContentsOfFile:systemVersionFile] ;
    > NSDictionary * dict = [NSPropertyListSerialization
    > propertyListFromData:data
    > mutabilityOption:NSPropertyListImmutable
    > format:NULL
    > errorDescription:nil
    > ] ;
    > NSLog (@"%@", dict) ;
    >
    >
    > The dictionary defines several keys : ProductUserVisibleVersion,
    > ProductVersion, …

    I don't think that's correct:

    <http://lists.apple.com/archives/carbon-dev/2007/Aug/msg00089.html>

    As always, it might be good to consider *why* you're looking for the
    OS version, as that will typically affect *how* you go about finding
    out. This might be of relevance:

    <http://developer.apple.com/documentation/DeveloperTools/Conceptual/cross_de
    velopment/index.html
    >

    Cheers,

    j o a r
  • As I understand it, the easiest way of doing this at runtime is like this:

    if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4)
    {
    // Call a Leopard-only method...

    }

    You can check for other major OS versions in the same way. See "Runtime Version Check" in the Developer Release Notes here:

    http://developer.apple.com/releasenotes/Cocoa/AppKit.html

    All the best,
    Keith

    -- ORIGINAL MESSAGE --

    Hi All,

            Is there any way to know the operating system version i.e

    either Leopard or Tiger ?

            Please let me know if you have any concern(s).

    Thanks,

    JanakiRam.

          ____________________________________________________________________________________
    Be a better pen pal.
    Text or chat with friends inside Yahoo! Mail. See how.  http://overview.mail.yahoo.com/
  • Remember that NSAppKitVersionNumber10_4 is not actually defined in the
    10.4 *or* 10.5 AppKit header. Remember to do this somewhere appropriate:

    #ifndef NSAppKitVersionNumber10_4
        #define NSAppKitVersionNumber10_4 824
    #endif

    --
    m-s

    On 17 Nov, 2007, at 13:49, Keith Blount wrote:

    > As I understand it, the easiest way of doing this at runtime is like
    > this:
    >
    >
    > if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4)
    > {
    > // Call a Leopard-only method...
    >
    > }
    >
    >
    > You can check for other major OS versions in the same way. See
    > "Runtime Version Check" in the Developer Release Notes here:
    >
    >
    > http://developer.apple.com/releasenotes/Cocoa/AppKit.html
    >
    >
    > All the best,
    > Keith
    >
    >
    >
    > -- ORIGINAL MESSAGE --
    >
    >
    > Hi All,
    >
    >
    >
    >
    > Is there any way to know the operating system version i.e
    >
    > either Leopard or Tiger ?
    >
    >
    >
    >
    > Please let me know if you have any concern(s).
    >
    >
    >
    >
    > Thanks,
    >
    > JanakiRam.
    >
    >
    >
    >
    >
    > ____________________________________________________________________________________
    > Be a better pen pal.
    > Text or chat with friends inside Yahoo! Mail. See how.  http://overview.mail.yahoo.com/
  • On Nov 19, 2007, at 7:33 AM, Michael Watson wrote:

    > Remember that NSAppKitVersionNumber10_4 is not actually defined in
    > the 10.4 *or* 10.5 AppKit header.

    It's certainly present in the 10.5 SDK.  It's defined in
    NSApplication.h along with the other version numbers.

    --
    adam
  • Ah, yeah, I don't know why I was thinking they'd left it out in 10.5.
    That's why it's wrapped in an #ifndef! :-)

    --
    m-s

    On 19 Nov, 2007, at 10:50, Adam R. Maxwell wrote:

    >
    > On Nov 19, 2007, at 7:33 AM, Michael Watson wrote:
    >
    >> Remember that NSAppKitVersionNumber10_4 is not actually defined in
    >> the 10.4 *or* 10.5 AppKit header.
    >
    > It's certainly present in the 10.5 SDK.  It's defined in
    > NSApplication.h along with the other version numbers.
    >
    > --
    > adam
    >
  • In addition to previous suggestions (Carbon API, AppKit #define, etc),
    it's also possible to use the sysctl() function to get just about any
    piece of information about the current hardware and software
    environment (cores, active cores, speed, memory, really darn near
    anything).  Those other methods are easier to use (and NSProcessInfo
    has some nice new API on Leopard), but this function seems under
    appreciated, so I recommend you look at the man page.  I determined
    the kernel OS revision #s experimentally.

    #include <stdio.h>
    #include <sys/sysctl.h>

    int main (int argc, const char * argv[]) {
    int preLeopardOS = 1;
    int sels[2] = { CTL_KERN , KERN_OSRELEASE };
    char buffer[128];
    size_t bufsize = sizeof(buffer);
    if (0 == sysctl(sels, 2, buffer, &bufsize, NULL, 0)) {
      preLeopardOS = (strcmp(buffer, "9") < 0); // kern.osrevision = 8.8.1
    on Tiger, 9.x on Leopard
    }

        printf("Hello, %s\n", (preLeopardOS) ? "Tiger" : "Leopard");
        return 0;
    }

    One issue is that this will tell you the OS that is running, but NOT
    the linkage of your application.  For example, if you build against
    the 10.4 SDK, and run on Leopard, the framework will try to give you
    10.4 behavior, even though the OS is Leopard.  This behavior could be
    desirable, or not, depending on what you need.

    - Ben
  • I would be careful about using sysctl to determine the OS X version
    number. I could be wrong so please correct me if I am, but I believe
    it is possible to upgrade the Darwin independently of OS X since
    Darwin is open source. (I've heard of situations where people needed
    certain functionality from the kernel that was not yet shipped by
    Apple, so upgrading Darwin was the recommended solution.)

    As far as I know, sysctl only can tell you the kernel version, not the
    OS X version sitting on top of it.

    -Eric

    On 11/19/07, Ben Trumbull <trumbull...> wrote:
    > In addition to previous suggestions (Carbon API, AppKit #define, etc),
    > it's also possible to use the sysctl() function to get just about any
    > piece of information about the current hardware and software
    > environment (cores, active cores, speed, memory, really darn near
    > anything).  Those other methods are easier to use (and NSProcessInfo
    > has some nice new API on Leopard), but this function seems under
    > appreciated, so I recommend you look at the man page.  I determined
    > the kernel OS revision #s experimentally.
    >
    > #include <stdio.h>
    > #include <sys/sysctl.h>
    >
    > int main (int argc, const char * argv[]) {
    > int preLeopardOS = 1;
    > int sels[2] = { CTL_KERN , KERN_OSRELEASE };
    > char buffer[128];
    > size_t bufsize = sizeof(buffer);
    > if (0 == sysctl(sels, 2, buffer, &bufsize, NULL, 0)) {
    > preLeopardOS = (strcmp(buffer, "9") < 0); // kern.osrevision = 8.8.1
    > on Tiger, 9.x on Leopard
    > }
    >
    > printf("Hello, %s\n", (preLeopardOS) ? "Tiger" : "Leopard");
    > return 0;
    > }
    >
    > One issue is that this will tell you the OS that is running, but NOT
    > the linkage of your application.  For example, if you build against
    > the 10.4 SDK, and run on Leopard, the framework will try to give you
    > 10.4 behavior, even though the OS is Leopard.  This behavior could be
    > desirable, or not, depending on what you need.
    >
    > - Ben
    >
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today