If I go to "System Settings" -> "General" -> "About", it says "MacBook Air" and below that "M2, 2022"
How can I get these strings programatically? The following C code gets me
#include <stdio.h>
#include <sys/sysctl.h>
int main() {
static const unsigned namelen = 2;
int name[namelen] = {CTL_HW, HW_PRODUCT};
char buffer[256];
size_t bufferSize = sizeof(buffer);
if (0 != sysctl(name, namelen, buffer, &bufferSize, NULL, 0)) {
perror("sysctl");
return 1;
}
printf("%s\n", buffer);
}
the string "Mac14,2", which is the hardware model identifier. But I want to get the user-friendly model name, e.g. "MacBook Air (13-inch, M2, 2022)". How can I do this?
The technique suggested there are unsupported.
Using random properties you find in I/O registry is not something we support. The supported properties are those with symbolic constants in IOKit framework.
Similarly, classes that start with Apple
are not considered API in I/O Kit.
And similar for undocumented property lists lurking deep in Apple frameworks.
Now, this won’t stop people from using this stuff, but it’s not the path to long-term binary compatibility. I regularly see threads here on DevForums from folks who’ve ignored these rules and found that their software no longer works with a new OS release or new hardware.
Regardless of what else you do here, please file an enhancement request for an API to get the info you need (and post your bug number, just for the record).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"