AppleScript: Set Display Brightness
I’ve been using AppleScript for years now, but I’ve never had the opportunity to become really good at it. I can do a few simple things, but once I get beyond that, I pretty much have to turn to the web. So it was, this morning: my office has two large windows in it, so the ambient light varies quite a bit from day to day and hour to hour. I finally decided that I’m sick and tired of adjusting the brightness on three different displays—not to mention hoping that they’re all exactly the same—on a regular basis. So as usual, I turned to the web.
After a few less useful hits, I finally came to an old blog post called “Change Monitor Brightness Using AppleScript.” It was exactly what I needed, with three exceptions:
- Since it’s four years old, it hasn’t been updated for Mountain Lion.
- It isn’t designed to change multiple displays concurrently.
- It doesn’t include the ability to specify the brightness level, on the fly.
Having solved all three of these problems, I post my results, in hopes that it may help someone else:
set brightness_level to (text returned of (display dialog "Set Brightness Level" default answer ".875" buttons {"Cancel", "OK"} default button "OK")) as numbertell application "System Preferences"activateset current pane to pane "com.apple.preference.displays"tell application "System Events"set j to (count windows of process "System Preferences")repeat with i from 1 to jset value of slider 1 of group 1 of tab group 1 of window i of process "System Preferences" to brightness_levelend repeatend tellquitend tell
Enjoy! :-)
thank you, just want i needed, first google result :)
ReplyDeleteYou’re very welcome, 3DDR! :-)
ReplyDelete