2 years ago
#22695

ixany
Detect Mac device color (Swift)
I am wondering if it is possible to detect the color of the Mac my app is running on?
extension NSScreen {
var cgDirectDisplayId: CGDirectDisplayID? {
let description = self.deviceDescription
return description[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID
}
var modelNumber: String? {
guard let displayId = self.cgDirectDisplayId else {
return nil
}
return String(format: "%02X", CGDisplayModelNumber(displayId)).lowercased()
}
}
... this gives me the modelNumber
of NSScreen
and enables me to differentiate if it’s an iMac or MacBook for example. However, it lacks information about the devices color and also doesn’t help with devices like the Mac mini which can have multiple colors (silver/grey) but comes without an built-in display.
Any hint would be much appreciated!
swift
macos
core-graphics
iokit
swift
macos
core-graphics
iokit
0 Answers
Your Answer