0

Screen dimming is a great feature when moving to differently lit rooms. However, if the MacBook is facing a bright window, and the user is thus backlit, then the sensor goes haywire.

I need to create some of script to disable auto-dim during sunset hours. How can I access the dimmer feature from bash, AppleScript, or any other language?

  • 1
    Possible duplicate of How can I dim the screen from Terminal? – Gleland Jun 14 '17 at 1:05
  • 1
    To anyone voting to close this as a duplicate of How can I dim the screen from Terminal?, it is not a duplicate of How can I dim the screen from Terminal?! This question is not about setting the brightness level, it's about disabling "Automatically adjust brightness" in the System Preferences for the Display! – user3439894 Jun 14 '17 at 3:05
3

This AppleScript may or may not work on your system. On my Mac book Pro running the latest version of Sierra, this following code enables the "Automatically adjust brightness" checkbox If your current time is between 6 am and 6 pm, Otherwise it disables that checkbox If it is already selected.

if hours of (current date) is greater than 6 then
    if hours of (current date) is less than 18 then
        tell application "System Preferences"
            reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
        end tell
        tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
            tell checkbox "Automatically adjust brightness" of group 2 of tab group 1 to if value is 0 then click
        end tell
    else
        tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
            tell checkbox "Automatically adjust brightness" of group 2 of tab group 1 to if value is 1 then click
        end tell
    end if
end if
tell application "System Preferences"
    quit
end tell

You can adjust the hours values at the top of the script to suit your needs

If your display preferences looks like this picture... This script should work for you.

enter image description here

-2

You can do it by following the instructions from here provided by daviesgeek

Dimmer:

tell application "System Events"
        key code 107
    end tell

Brighter:

tell application "System Events"
        key code 113
    end tell

You can save these as .script files and then run them from the CLI like this:

osascript ~/Path/to/File

You can also do it this way, but that requires more setup.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .