1

I am trying to create a applescript that puts my brightness to the max or minimum, but I don't know how to. I am trying to use this script

    repeat 10 times
    tell application "System Events"
        key code 122
        delay 0.1
    end tell
end repeat

but nothing happens.

1

Provided the necessary accessibility privileges are granted that permits UI scripting, this script programmatically adjusts the brightness of your screen by way of System Preferences:

tell application "System Preferences"
    set current pane to pane id "com.apple.preference.displays"
    reveal anchor "displaysDisplayTab" of current pane
end tell

tell application "System Events" to tell ¬
    process "System Preferences" to tell ¬
    window 1 to tell ¬
    tab groups to tell ¬
    groups to tell ¬
    sliders to set its value to 0.5 -- 0.0 to 1.0

quit application "System Preferences"

You can set that value you see to any decimal value between 0.0 (minimum brightness, display off) and 1.0 (maximum brightness).

| improve this answer | |
1

If I might suggest another alternative, I would offer the brightness command, installed from either https://github.com/nriley/brightness or brew install brightness.

Then you can easily switch to any brightness level between 0 (dark) and 1 (full power) with brightness .5 being ½-full.

You could call brightness from an AppleScript if this to be an AppleScript solution.

| improve this answer | |
-1

With your apple script attempt this is possible.

To dim your display to minimum brightness:

repeat 32 times
    tell application "System Events"
        key code 107
    end tell
end repeat

To brighten up your display to maximum brightness:

repeat 32 times
    tell application "System Events"
        key code 113
    end tell
end repeat
| improve this answer | |

You must log in to answer this question.

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