get display name and vendor info by IOKit framework

Hello, What is the best and Apple recommended way to get display name and its vendor information?

  1. The CoreGraphics framework provides ModelNumber and VendorNumber only.
  2. Looks like IOKit does not provide any documented way at all.

Are there any daemon safe way to get such information?

Thank you in advance, Pavel

Answered by DTS Engineer in 833683022

Display and vendor information can be retrieved using Core Graphics' Quartz Display Services routines as shown below. As you have mentioned, the CGDisplayModelNumber(_:) and CGDisplayVendorNumber(_:) routines return numbers.

import Foundation
import CoreGraphics
var mainDisplay: CGDirectDisplayID = CGMainDisplayID()
var displayCount: UInt32 = 0
let maxDisplays: UInt32 = 100
let displaysList: UnsafeMutablePointer<CGDirectDisplayID> = UnsafeMutablePointer<CGDirectDisplayID>.allocate(capacity: Int(maxDisplays))
var status: CGError = CGGetOnlineDisplayList(maxDisplays, displaysList, &displayCount)
guard status == CGError.success else {
fatalError("Couldn't get online displays list")
}
for displayIndex: Int in 0..<Int(displayCount) {
let nthDisplayID: CGDirectDisplayID = displaysList[displayIndex]
print("Display #\(displayIndex):")
print(" main display: \(CGDisplayIsMain(nthDisplayID))")
print(" online: \(CGDisplayIsOnline(nthDisplayID))")
print(" model number: \(CGDisplayModelNumber(nthDisplayID))")
print(" serial number: \(CGDisplaySerialNumber(nthDisplayID))")
print(" unit number: \(CGDisplayUnitNumber(nthDisplayID))")
print(" vendor number: \(CGDisplayVendorNumber(nthDisplayID))")
if let displayModes: CFArray = CGDisplayCopyAllDisplayModes(nthDisplayID, nil ) {
// dump(displayModes)
}
}

The CGDisplayIOServicePort(_:) routine returns a I/O Kit service port for the specified display but any results you are able to obtain using this service port are undocumented and subject to change at any time without notice. Also, use of this routine has been deprecated.

If you require additional information not provided by the Quartz Display Services routines then please file an enhancement request asking for routines providing the additional information you are interested in getting about connected displays. You can file an enhancement request using Feedback Assistant. Once you file the request, please post the Feedback number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

Accepted Answer

Display and vendor information can be retrieved using Core Graphics' Quartz Display Services routines as shown below. As you have mentioned, the CGDisplayModelNumber(_:) and CGDisplayVendorNumber(_:) routines return numbers.

import Foundation
import CoreGraphics
var mainDisplay: CGDirectDisplayID = CGMainDisplayID()
var displayCount: UInt32 = 0
let maxDisplays: UInt32 = 100
let displaysList: UnsafeMutablePointer<CGDirectDisplayID> = UnsafeMutablePointer<CGDirectDisplayID>.allocate(capacity: Int(maxDisplays))
var status: CGError = CGGetOnlineDisplayList(maxDisplays, displaysList, &displayCount)
guard status == CGError.success else {
fatalError("Couldn't get online displays list")
}
for displayIndex: Int in 0..<Int(displayCount) {
let nthDisplayID: CGDirectDisplayID = displaysList[displayIndex]
print("Display #\(displayIndex):")
print(" main display: \(CGDisplayIsMain(nthDisplayID))")
print(" online: \(CGDisplayIsOnline(nthDisplayID))")
print(" model number: \(CGDisplayModelNumber(nthDisplayID))")
print(" serial number: \(CGDisplaySerialNumber(nthDisplayID))")
print(" unit number: \(CGDisplayUnitNumber(nthDisplayID))")
print(" vendor number: \(CGDisplayVendorNumber(nthDisplayID))")
if let displayModes: CFArray = CGDisplayCopyAllDisplayModes(nthDisplayID, nil ) {
// dump(displayModes)
}
}

The CGDisplayIOServicePort(_:) routine returns a I/O Kit service port for the specified display but any results you are able to obtain using this service port are undocumented and subject to change at any time without notice. Also, use of this routine has been deprecated.

If you require additional information not provided by the Quartz Display Services routines then please file an enhancement request asking for routines providing the additional information you are interested in getting about connected displays. You can file an enhancement request using Feedback Assistant. Once you file the request, please post the Feedback number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

hello,

  1. As far as I know, Quartz Display Services is not daemon safe way. Moreover, CGDisplayUnitNumber() returns value which may vary across login sessions.
  2. CGDisplayIOServicePort() is deprecated.

Are there any other way which is based on IOKit framework?

Thank you for the help!

Anything display related using I/O Kit directly is undocumented and subject to change without notice at any time. I recommend filing a feature request for any special requirements you may have.

You can file an enhancement request using Feedback Assistant. Once you file the request, please post the Feedback number here and we will route it to the appropriate team internally.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

thank you!

get display name and vendor info by IOKit framework
 
 
Q