3

My cocoa application needs to disable the display's setting for 'Automatically adjust brightness'. This is the checkbox that can be found in System Preferences -> Displays

While I have found some great resources on how to get/set the brightness level, I have yet to find anything to help me disable the automatic setting.

So far this is what I have tried and this is not working, perhaps I have something wrong in the code?

This is in Swift.

    // get the light sensor service
    let lightSensor: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault,
                                                                IOServiceMatching("AppleLMUController"))

    // connect to the service
    var port: io_connect_t = 0
    IOServiceOpen(lightSensor, mach_task_self_, 0, &port)

    // set the property to false to turn off light sensor
    let offState: Bool = false
    let result: kern_return_t = IOConnectSetCFProperty(lightSensor, 
                                                       kIODisplayAmbientLightSensorKey, 
                                                       offState)

    // print the result
    if result == kIOReturnSuccess { print("yay") }
    else { print("boo") }

    // disconnect from service
    IOConnectRelease(lightSensor)

Of course my output is 'boo' since this is failing. Can someone point out what I'm doing wrong?

I have also attempted using the following but I am not sure what values the kIODisplayAmbientLightSensorKey property takes.

var offState: Float = 0.0
IODisplaySetFloatParameter(service, 0, kIODisplayAmbientLightSensorKey, offState)

Additionally, I have come across kIODisplayOptionDimDisable and kIODisplayOptionBacklight but I believe what I need is to do is disable the AmbientLightSensor?

Mary Martinez
  • 314
  • 5
  • 12

0 Answers0