- Mac App Store safe
Manually map model identifier to icon name and then use e.g
[[NSWorkspace sharedWorkspace] iconForFileType:@"com.apple.macbookair"];
or
[NSImage imageNamed:NSImageNameComputer]
If you need higher resolution than imageNamed provides use
OSType code = UTGetOSTypeFromString((CFStringRef)CFSTR("root"));
NSImage *computer = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(code)];
where "root" string is from IconsCore.h header file (kComputer).
Copy this plist to get the identifiers (do not access it from app sandbox)
/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist
- Mac App Store unsafe
Link Private Framework SPSupport.Framework with your binary
Add FrameWork Search path variable
$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks
Add following interface into your project
#import <Cocoa/Cocoa.h>
@interface SPDocument : NSDocument
- (NSImage *)modelIcon;
- (id)computerName;
- (id)serialNumber;
- (id)modelName;
@end
Call in your code:
SPDocument *document = [[SPDocument alloc] init];
NSImage *icon = [document modelIcon];
- Hardest way
Figure out CoreFoundation dance with this private function (this code is illustration, find correct types, number of params and release properly)
output = _LSCreateDeviceTypeIdentifierWithModelCode((CFStringRef)@"MacBookPro6,2");
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType: output];
EDIT:
I just realized that you need option number 1,3 (icon for given model). GL fighting this.
EDIT2
Method 3 added. Changed the order and added under number 1.
EDIT3
New UTIs for the colored version
com.apple.macbook-retina-silver
com.apple.device-model-code
MacBook8,1@ECOLOR=225,225,223
com.apple.macbook-retina-gold
com.apple.device-model-code
MacBook8,1@ECOLOR=235,215,191
com.apple.macbook-retina-space-gray
com.apple.device-model-code
MacBook8,1@ECOLOR=155,158,159
MacBook8,1@ECOLOR=157,157,160
NSImage *image =[[NSWorkspace sharedWorkspace] iconForFileType:@"com.apple.macbook-retina-gold"];
How to get model number/identifier (sysctl hw.model was replaced by system_profiler)?
NSPipe *outputPipe = [NSPipe pipe];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/sbin/system_profiler"];
[task setArguments:@[@"SPHardwareDataType"]];
[task setStandardOutput:outputPipe];
[task launch];
[task waitUntilExit];
NSData *outputData = [[outputPipe fileHandleForReading] readDataToEndOfFile];
NSString *hardware = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
And parse Model identifier or your propertylistserialization