Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

robvas

macrumors 68040
Original poster
Mar 29, 2009
3,240
629
USA
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

Moderator
Staff member
Aug 9, 2009
10,743
8,417
A sea of green
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

macrumors 6502
Mar 12, 2010
274
0
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:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.