r/applescript • u/Davewehr18214 • Mar 19 '23
Adjust Brightness with AppleScript?
I have a 2022 14” MBP (M1) and nothing I find online seems to do the trick. I am just trying to use AppleScript to set brightness up to a specific level.
1
Upvotes
2
u/mar_kelp Mar 19 '23
I don't see an easy way to do it in AppleScript directly (key codes don't seem to work for the 120/122 brightness keys and there are a few sh examples with helper apps).
However, Shortcuts in macOS can adjust the screen brightness. Search for "Set Brightness" in the Scripting category when creating a new Shortcut.
If AppleScript is necessary, trigger the Shortcut as part of a larger AppleScript:
Alternately, you can trigger AppleScript from within Shortcuts before or after the "Set Brightness" command.
2
u/copperdomebodha Mar 20 '23 edited Mar 20 '23
I don't see your OS listed. Assuming you're running Ventura...
2
u/jblx6 Mar 19 '23
You can do it with a shell script rather than use a shortcut. You need to install the command line tool ‘brightness’.
https://github.com/nriley/brightness
Or just ‘brew install brightness’ if you use homebrew…
And then you can just run the following in a AppleScript:
do shell script "/usr/local/bin/brightness 1"
(Or whatever path you have installed it at)