11

I've been digging around in the kernel code repo for days, but I just can't find this anywhere.

I want to disable/enable/detect the state of the ambient-light sensor based screen dimming that many of the higher end Mac laptops have. This is the dimming that is activated by the "Automatically Adjust Brightness" checkbox in the Display control panel.

Note that I'm NOT talking about the halfdim setting that causes the screen to dramatically dim right before it sleeps. I'm talking about the setting that dims the screen in dark rooms and brightens it in light rooms, which is different.

If anybody can even point me in the right direction I'd be greatfull. I assume it's handled somewhere in IOKit, probably either IOGraphics where screen brightness is handled, or somewhere in IOKit/pwr_mgt, but I just can't find it.

Thanks

Edit: I know you can kind of do this this by addressing System Preferences with AppleScript. I'm looking for the real way, if it exists.

peterjb
  • 3,189
  • 2
  • 17
  • 12
  • 1
    possible duplicate of [Any sample code on getting data from sensors on Mac?](http://stackoverflow.com/questions/4628547/any-sample-code-on-getting-data-from-sensors-on-mac) – jscs Sep 02 '12 at 20:48
  • 1
    Apple hasn't been open-sourcing hardly any new drivers, approximately since the Intel transition, so you'll probably need to do some sleuthing to find these (private) APIs. Amit Singh's old example is probably a good start - newer models of Mac may use a different driver, though (I don't have a model with a light sensor, so I couldn't tell you). You should be able to find the device and driver class via the `ioreg` or `IORegistryExplorer` tools. If the API calls have changed, you can probably trace the IOService user methods used by existing apps, such as System Preferences. – pmdj Sep 03 '12 at 07:49

4 Answers4

6

This isn't an API, per sé.. but there are many ways to control launchd via an API.

sudo launchctl stop com.apple.AmbientDisplayAgent

sudo launchctl remove com.apple.AmbientDisplayAgent

Ta Da!

Alex Gray
  • 16,007
  • 9
  • 96
  • 118
5

Trying to do this on Mavericks was unsuccessful for me. After some research I've discovered you need to use the following command:

defaults write /Library/Preferences/com.apple.iokit.AmbientLightSensor "Automatic Display Enabled" -bool TRUE

I believe specifying the full path is necessary else it would default to the user's Library/Preferences which is incorrect. Being in that directory in Terminal doesn't work either due to the way defaults works.

This does not update the tickbox in System Preferences -> Displays though.

Oliver Martin
  • 213
  • 2
  • 7
1

Change the "Automatically Adjust Brightness" setting using the defaults command:

defaults write com.apple.BezelServices dAuto -boolean false

Also retrieve the current setting using the defaults command:

defaults read com.apple.BezelServices dAuto

AppleScript equivalent:

do shell script "defaults write com.apple.BezelServices dAuto -boolean false"

Use true to enable and false to disable the feature.
You might need to logon again for the changes to take effect.

Anne
  • 26,765
  • 9
  • 65
  • 71
  • Thanks, but this isn't working on my MacBook Pro. I want to do this as part of a program, anyway--I'm looking for an API--so the log out/in bit is a deal breaker, too. – peterjb Sep 08 '12 at 01:00
  • This used to work but apparently not these days (I'm on macOS 10.14 Mojave) – dentarg Aug 30 '19 at 08:07
1

Posting this as it might help someone who like me had already disabled the ambient light sensing but still found their computer was dimming when waking from sleep. Turns out I also needed uncheck the box to "Slightly dim the display while on battery power"

System Preferences > Battery > Slightly dim the display while on battery power

See the image below:

uncheck auto dim on battery

tnrich
  • 8,006
  • 8
  • 38
  • 59