Search code examples
macos-high-sierramacos-mojave

macOS Hight Sierra / Mojave: Programmatically get value of "System Preferences -> Accessibility -> Display -> Increase contrast"


How programmatically get value of Increase contrast setting on macOS Hight Sierra? Also interesting to know how to observe that value change.

Full path to system preference is System Preferences -> Accessibility -> Display -> Increase contrast.

enter image description here

On macOS Mojave it can be achieved via effectiveAppearance.bestMatch API call like below.

open override func layout() {
  super.layout()
  if #available(OSX 10.14, *) {
     if let value = effectiveAppearance.bestMatch(from: [.aqua, .darkAqua, .accessibilityHighContrastAqua, .accessibilityHighContrastDarkAqua]) {

        switch value {
        case .aqua:
           setupAppearance(.light)
        case .darkAqua:
           setupAppearance(.dark)
        case .accessibilityHighContrastAqua:
           setupAppearance(.highContrastLight)
        case .accessibilityHighContrastDarkAqua:
           setupAppearance(.highContrastDark)
        default:
           break
        }

     }
  }
}

Solution

  • Starting on macOS 10.10 you can use this API of NSWorkspace.

    https://developer.apple.com/documentation/appkit/nsworkspace/1526290-accessibilitydisplayshouldincrea