PDA

View Full Version : Detecting system type?




robvas
Jul 9, 2012, 10:22 PM
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.



chown33
Jul 9, 2012, 10:36 PM
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.

willieva
Jul 10, 2012, 08:26 AM
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;
uname(&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:)

kryten2
Jul 10, 2012, 02:28 PM
The output of sysctl hw.model on a 1,42 GHz PowerPC G4 Mac mini is :

hw.model: PowerMac10,1