Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Change the screen brightness using AppleScript

I am making a script - and I want it to change the built-in display brightness up or down so many points... but can't find the function I need.

Please help!

Thanks
Richard

iBook G4, Mac OS X (10.4.3)

Posted on Dec 10, 2005 7:54 PM

Reply
Question marked as Best reply

Posted on Dec 11, 2005 12:02 AM

Hi Richard,

This works for me:

tell application "System Preferences" to set current pane to pane "Displays"
tell application "System Events"
tell process "System Preferences"
tell tab group 1 of window 1
click radio button 1
tell slider 1 of group 2
set CurVal to value
set value to CurVal + 0.2
end tell
end tell
end tell
end tell
quit application "System Preferences"

Notes about the above script:

1.) You need to have " Enable access for assistive devices" turned on in the " Universal Access" section of " System Preferences" for the script to work correctly.

2.) The values you can set the slider to are from 0 to 1

I have searched high and low for a way to change the display brightness without resorting to "UI Scripting" but have fallen flat every time I've looked! It's a major pet peeve of mine actually!

Hope this script helps you out...

iBook G4 1GHz Mac OS X (10.4.3) 640 MB RAM
5 replies
Question marked as Best reply

Dec 11, 2005 12:02 AM in response to Richard Henry

Hi Richard,

This works for me:

tell application "System Preferences" to set current pane to pane "Displays"
tell application "System Events"
tell process "System Preferences"
tell tab group 1 of window 1
click radio button 1
tell slider 1 of group 2
set CurVal to value
set value to CurVal + 0.2
end tell
end tell
end tell
end tell
quit application "System Preferences"

Notes about the above script:

1.) You need to have " Enable access for assistive devices" turned on in the " Universal Access" section of " System Preferences" for the script to work correctly.

2.) The values you can set the slider to are from 0 to 1

I have searched high and low for a way to change the display brightness without resorting to "UI Scripting" but have fallen flat every time I've looked! It's a major pet peeve of mine actually!

Hope this script helps you out...

iBook G4 1GHz Mac OS X (10.4.3) 640 MB RAM

Dec 11, 2005 8:26 AM in response to Richard Henry

I have a further question... 🙂

It is a PowerBook plugged into an external (non-Apple) display. When the PowerBook isn't plugged into the display, the brightness script works fine, however- I have the toolbar set to automatically be on the second monitor when the second monitor is available. When the toolbar is on the second monitor, the script no longer works, returning the error:

System Events got an error: NSReceiverEvaluationScriptError: 4

I am guessing that I recieve this error because the brightness slider is now no longer on the main window, but the display properties window on the PowerBook's monitor (which isn't the primary display).

You've been a great help so far, thank you so much!

Richard

Dec 11, 2005 8:30 AM in response to Richard Henry

I just figured it out!

tell application "System Preferences" to set current pane to pane "Displays"

tell application "System Events"
tell process "System Preferences"
tell tab group 1 of window 0 -- Change this to 'window 0'
click radio button 1
tell slider 1 of group 2
set CurVal to value
set value to CurVal - 1
end tell
end tell
end tell
end tell

quit application "System Preferences"


Thanks again!

Dec 11, 2005 10:56 AM in response to Richard Henry

You're welcome Richard,

I just now got back to my computer and noticed you had another question for me. Glad to here you were able to figure it out on your own. I wish I would've know that that was the direction you were trying to go in the first place so I could've posted an appropriate script for your particular situation. All in all I'm glad you got it working for your needs and that the script I posted was able to help you out.

iBook G4 1GHz Mac OS X (10.4.3) 640 MB RAM

Change the screen brightness using AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.