Detecting system type?

Discussion in 'Mac Programming' started by robvas, Jul 9, 2012.

  1. robvas macrumors 68030

    Mar 29, 2009
    What's the best way for an App to figure out what machine and version it's running on? For instance, if you wanted to make a program only have a certain feature if it's running on a Mac Mini.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    It depends on exactly how you want to qualify "machine" and "version".

    For the specific case of "a Mac mini", I would probably use the sysctl name "hw.model", which in the case of a Mac mini would return a C string like "Macmini1,1" or "Macmini2,1". Because all models of Mac mini (well Intel-based) have the string "Macmini", that's what I'd look for. Specific models over time have different "n,m" values, so if that's what you mean by "version", then use that. Otherwise you'll have to describe exactly what "version" represents.

    If I had to qualify PowerPC-based Mac minis, I'm not sure if sysctl hw.model would work or not, I'd have to test it first.

    There are a lot of other hardware qualifiers in the "hw" family of sysctl names. See the man page for sysctl. There's both a command called sysctl, as well as a C function. So if you're shell scripting or AppleScripting, use the command. Otherwise use the C function. And you'll probably want to use the C function sysctlbyname, because figuring out sysctl's MIB stuff is way too hard unless you're really hard-core.
  3. willieva macrumors 6502

    Mar 12, 2010
    uname -a from the command line gives the info you want.

    In C you can fill a utsname structure with the uname function.

    struct utsname info;

    sysctl is for getting and setting kernel parameters. You can use it to get the info you want but it it's not as simple as uname.


    Never mind, you won't be able to get that specific with uname. Guess I should have read the post more carefully:)
  4. kryten2 macrumors 6502a

    Mar 17, 2012
    The output of sysctl hw.model on a 1,42 GHz PowerPC G4 Mac mini is :

    hw.model: PowerMac10,1

Share This Page