How to script brightness turning down and up? 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.
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).