Skip to content

Instantly share code, notes, and snippets.

@TomLiu
Created September 16, 2013 01:42
Show Gist options
  • Save TomLiu/6575851 to your computer and use it in GitHub Desktop.
Save TomLiu/6575851 to your computer and use it in GitHub Desktop.
Get the localized name of a display, given the displ
/* Get the localized name of a display, given the display ID. */
-(NSString *)displayNameFromDisplayID:(CGDirectDisplayID)displayID
{
NSString *displayProductName = nil;
/* Get a CFDictionary with a key for the preferred name of the display. */
NSDictionary *displayInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
/* Retrieve the display product name. */
NSDictionary *localizedNames = [displayInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
/* Use the first name. */
if ([localizedNames count] > 0)
{
displayProductName = [[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] retain];
}
[displayInfo release];
return [displayProductName autorelease];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment