mathiasbynens / dotfiles

:wrench: .files, including ~/.macos — sensible hacker defaults for macOS
https://mths.be/dotfiles
MIT License
30.35k stars 8.73k forks source link

Disable automatically adjust brightness #329

Open philipwalton opened 10 years ago

philipwalton commented 10 years ago

In System Preferences > Displays there's a checkbox that is checked by default to "Automatically Adjust Brightness".

I've looked for ways to turn this off programmatically but haven't found anything. I thought I'd suggest it here in hopes that someone else knows and it's of general interest to the community.

jfelchner commented 9 years ago

@philipwalton try this

s10wen commented 9 years ago

@jfelchner looks like that link 404s now.

I did find this: http://stackoverflow.com/questions/12239496/disable-ambient-light-sensor-screen-dimming-programmatically-on-os-x

and tried: defaults write com.apple.BezelServices dAuto -boolean false

But it didn't seem to work for me, has anyone else had any luck?

jfelchner commented 6 years ago

@philipwalton can we go ahead and close this out please?

Changes in High Sierra are making it a requirement that the majority of these settings changes are going to have to be done with AppleScript rather than using defaults commands.

KennethSundqvist commented 6 years ago

I have not found a nice way to do this so here's an AppleScript I wrote for toggling the setting.

AppleScript must open the System Preferences and click around and crap, but that's the way they want to do stuff I guess...

tell application "System Preferences"
  activate
  set current pane to pane "com.apple.preference.displays"
end tell

tell application "System Events"
  tell window "Built-in Retina Display" of application process "System Preferences"
    -- The tab group isn't loaded right away when we've just opened the "Displays" preferences
    repeat until exists tab group 1
    end repeat
    tell tab group 1
      click radio button "Display"
      set cb to checkbox "Automatically adjust brightness" of group 1
      click cb
      if value of cb is 0 then
        display notification "Disabled automatically adjust brightness"
      else
        display notification "Enabled automatically adjust brightness"
      end if
    end tell
  end tell
end tell

tell application "System Preferences" to quit