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?

2 Answers2

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

wch1zpink
  • 7,571
-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.

Gleland
  • 478