This page maintains an up-to-date ASCII property list for translating sysctl hw.model into human-readable strings.
Save the following text as a file named “Macintosh.dict”, and add it to your app’s (localized) Resources folder.
{ “ADP2,1” = “Developer Transition Kit”; “iMac,1” = iMac; “iMac4,1” = “iMac (Core Duo)”; “iMac5,1” = “iMac (Core 2 Duo)”; “iMac6,1” = “iMac (24-inch Core 2 Duo)”; “iMac7,1” = “iMac (Aluminum Core 2 Duo)”; “iMac8,1” = “iMac (Aluminum Core 2 Duo)”; “M43ADP1,1” = “Development Mac Pro”; “MacBook1,1” = “MacBook (Core Duo)”; “MacBook2,1” = “MacBook (Core 2 Duo)”; “MacBook3,1” = “MacBook (Core 2 Duo)”; “MacBook4,1” = “MacBook (Early 2008)”; “MacBookAir1,1” = “MacBook Air”; “MacBookPro1,1” = “MacBook Pro (15-inch Core Duo)”; “MacBookPro1,2” = “MacBook Pro (17-inch Core Duo)”; “MacBookPro2,1” = “MacBook Pro (17-inch Core 2 Duo)”; “MacBookPro2,2” = “MacBook Pro (15-inch Core 2 Duo)”; “MacBookPro3,1” = “MacBook Pro (15-inch or 17-inch LED, Core 2 Duo)”; “MacBookPro4,1” = “MacBook Pro (15-inch or 17-inch LED, Early 2008)”; “MacBookPro5,1” = “MacBook Pro (15-inch LED Unibody, Late 2008)”; “MacBookPro5,4” = “MacBook Pro (15-inch LED Unibody, Mid 2009)”; “Macmini1,1” = “Mac mini (Core Duo/Solo)”; “MacPro1,1” = “Mac Pro (Quad Xeon)”; “MacPro2,1” = “Mac Pro (Octal Xeon)”; “MacPro3,1” = “Mac Pro (Early 2008)”; “PowerBook1,1” = “PowerBook G3”; “PowerBook2,1” = iBook; “PowerBook2,2” = “iBook (FireWire)”; “PowerBook3,1” = “PowerBook G3 (FireWire)”; “PowerBook3,2” = “PowerBook G4”; “PowerBook3,3” = “PowerBook G4 (Gigabit Ethernet)”; “PowerBook3,4” = “PowerBook G4 (DVI)”; “PowerBook3,5” = “PowerBook G4 (867, 1 GHz)”; “PowerBook4,1” = “iBook G3”; “PowerBook4,2” = “iBook G3”; “PowerBook4,3” = “iBook G3”; “PowerBook5,1” = “PowerBook G4 (17-inch)”; “PowerBook5,2” = “PowerBook G4 (15-inch FW800)”; “PowerBook5,3” = “PowerBook G4 (17-inch 1.33 GHz)”; “PowerBook5,4” = “PowerBook G4 (15-inch 1.5/1.33 GHz)”; “PowerBook5,5” = “PowerBook G4 (17-inch 1.5 GHz)”; “PowerBook5,6” = “PowerBook G4 (15-inch 1.67/1.5 GHz)”; “PowerBook5,7” = “PowerBook G4 (17-inch 1.67 GHz)”; “PowerBook5,8” = “PowerBook G4 (Double-Layer SD, 15-inch)”; “PowerBook5,9” = “PowerBook G4 (Double-Layer SD, 17-inch)”; “PowerBook6,1” = “PowerBook G4 (12-inch)”; “PowerBook6,2” = “PowerBook G4 (12-inch DVI)”; “PowerBook6,3” = “iBook G4”; “PowerBook6,4” = “PowerBook G4 (12-inch 1.33 GHz)”; “PowerBook6,5” = “iBook G4”; “PowerBook6,7” = “iBook G4”; “PowerBook6,8” = “PowerBook G4 (12-inch 1.5 GHz)”; “PowerMac1,1” = “Power Macintosh G3 (B&W)”; “PowerMac1,2” = “Power Macintosh G4 (PCI-Graphics)”; “PowerMac10,1” = “Mac mini”; “PowerMac10,2” = “Mac mini”; “PowerMac11,2” = “Power Macintosh G5 (PCIe)”; “PowerMac12,1” = “iMac G5 (iSight)”; “PowerMac2,1” = “iMac (Slot-Loading)”; “PowerMac2,2” = “iMac (2000)”; “PowerMac3,1” = “Power Macintosh G4 (AGP-Graphics)”; “PowerMac3,2” = “Power Macintosh G4 (AGP-Graphics)”; “PowerMac3,3” = “Power Macintosh G4 (Gigabit Ethernet)”; “PowerMac3,4” = “Power Macintosh G4 (Digital Audio)”; “PowerMac3,5” = “Power Macintosh G4 (Quick Silver)”; “PowerMac3,6” = “Power Macintosh G4 (Mirrored Drive Doors)”; “PowerMac4,1” = “iMac (2001)”; “PowerMac4,2” = “iMac (Flat Panel)”; “PowerMac4,4” = “eMac G3”; “PowerMac4,5” = “iMac (17-inch Flat Panel)”; “PowerMac5,1” = “Power Macintosh G4 Cube”; “PowerMac6,1” = “iMac (USB 2.0)”; “PowerMac6,3” = “iMac (20-inch Flat Panel)”; “PowerMac6,4” = “eMac (USB 2.0)”; “PowerMac7,2” = “Power Macintosh G5”; “PowerMac7,3” = “Power Macintosh G5”; “PowerMac8,1” = “iMac G5”; “PowerMac8,2” = “iMac G5 (Ambient Light Sensor)”; “PowerMac9,1” = “Power Macintosh G5 (Late 2004)”; “RackMac1,1” = “Xserve G4”; “RackMac1,2” = “Xserve G4 (Slot-Loading)”; “RackMac3,1” = “Xserve G5”; “Xserve1,1” = “Xserve Xeon”; “Xserve2,1” = “Xserve Xeon”; }
and add these two methods to one of your classes:
#import <sys/sysctl.h>
(NSString *)hardwareModel
{
static NSString *hardwareModel = nil;
if (!hardwareModel) {
char buffer[128];
size_t length = sizeof(buffer);
if (sysctlbyname(“hw.model”, &buffer, &length, NULL, 0) == 0) {
hardwareModel = [[NSString allocWithZone:NULL] initWithCString:buffer encoding:NSASCIIStringEncoding];
}
if (!hardwareModel || [hardwareModel length] == 0) {
hardwareModel = @”Unknown”;
}
}
return hardwareModel;
}
(NSString *)computerModel { static NSString *computerModel = nil; if (!computerModel) { NSString *path, *hardwareModel = [self hardwareModel]; if ((path = [[NSBundle mainBundle] pathForResource:@”Macintosh” ofType:@”dict”])) { computerModel = [[[NSDictionary dictionaryWithContentsOfFile:path] objectForKey:hardwareModel] copy]; } if (!computerModel) { char buffer[128]; size_t length = sizeof(buffer); if (sysctlbyname(“hw.machine”, &buffer, &length, NULL, 0) == 0) { computerModel = [[NSString allocWithZone:NULL] initWithCString:buffer encoding:NSASCIIStringEncoding]; } } if (!computerModel || [computerModel length] == 0) { computerModel = [[NSString allocWithZone:NULL] initWithFormat:@”%@ computer model”, hardwareModel]; } } return computerModel; }
Revision History