问题
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.
回答1:
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.
回答2:
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.
回答3:
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!
来源:https://stackoverflow.com/questions/12239496/disable-ambient-light-sensor-screen-dimming-programmatically-on-os-x