Skip to content

Instantly share code, notes, and snippets.

@0xced
Created August 7, 2009 14:44
Show Gist options
  • Save 0xced/163933 to your computer and use it in GitHub Desktop.
Save 0xced/163933 to your computer and use it in GitHub Desktop.
Human readable string for a display name (as in the Displays preference pane)
#import <IOKit/graphics/IOGraphicsLib.h>
#import <IOKit/graphics/IOGraphicsTypes.h>
NSString* screenNameForDisplay(CGDirectDisplayID displayID)
{
NSString *screenName = nil;
NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
if ([localizedNames count] > 0) {
screenName = [[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] retain];
}
[deviceInfo release];
return [screenName autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment