1

I'm trying to get the name of the connected external display with Cocoa or CoreFoundation. With "name" I mean that string that appears in the title bar of the System Preferences window when editing Display preferences.

I couldn't find any API for that in NSScreen or in the Quartz Display Services.

But there has to be a way, because if I access the color space of the display like this:

CGColorSpaceRef colorSpace = CGDisplayCopyColorSpace(displayID);

and I log the color space's description I get:

<CGColorSpace 0x100113c20>
(kCGColorSpaceICCBased; kCGColorSpaceModelRGB; DELL 2408WFP)

enter image description here

DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • 1
    I did some poking around, and the description you're seeing when you print the colorspace is actually the name of the current ICC color profile. This is not necessarily the same as the current display name. That's not to say there's not another way to get it. – Ken Aspeslagh Oct 19 '12 at 19:33

1 Answers1

1

I found a solution in an other thread (I wonder why I didn't find that before...).

I updated it to be ARC compatible:

- (NSString *)screenNameForDisplay:(CGDirectDisplayID)displayID {
    NSString *screenName = @"";
    NSDictionary *deviceInfo = (__bridge NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
    NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
    if ([localizedNames count] > 0) {
        screenName = [localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]];
    }
    return screenName;
}
Community
  • 1
  • 1
DrummerB
  • 39,814
  • 12
  • 105
  • 142