Setting Display Brightness to a specific value?

Hello!
I've been using BTT for a few weeks, it's excellent.

I was wondering if anyone could help me achieve this: I want a button on the Touch Bar that sets my Macbook's display brightness to a specific value, in my case, to 0 (this is different than putting it to sleep).

I figured I need an Apple Script for this, however I was unable to create one. I found this thread: "Brightness Up (Small Step)" and "Brightness Down (Small Step)" there are some hints, and probably by using or modifying one of those scripts, I would be able to create my own.

Could anyone give me a hand? Thank you!

Well, found one! I leave it here, in case it works for someone else. You can set the value at the penultimate line, 0 is 0%, 1 is 100% brightness. Cheers!

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 -- 0.0 to 1.0
quit application "System Preferences"

There is an easier/faster way in the most current BetterTouchTool versions:

With Java Script:

callBTT('set_number_variable', {variable_name: 'BuiltInDisplayBrightness', to: 0.9});
returnToBTT('');

or alternatively with Apple Script:

tell application "BetterTouchTool"
set_number_variable  "BuiltInDisplayBrightness" to 0.6
end tell

Thank you! Works much faster. I have been trying to make an interactive button, like the "mute" one (on Golden Chaos it turns red if it's muted). This is the script they use to monitor the volume, and if it's on 0, it returns true and the icon turns red:

set currentVolume to get volume settings
if output muted of currentVolume is true then
return true
else
return false
end if

Is there any chance you got the equivalent of that code, but for brightness? That way I can turn the brightness button I've just created to red dynamically once brightness is 0... I sincerely appreciate your help and work Andreas! Cheers

You can get the current brightness with

JavaScript

let brightness = await callBTT('get_number_variable', {variable_name: 'BuiltInDisplayBrightness'});
returnToBTT(brightness);

AppleScript

tell application "BetterTouchTool"
set currentBrightness to get_number_variable  "BuiltInDisplayBrightness"
end tell

Does that help?

Thank you! That was exactly what I was looking for. With both your scripts, I was able to get an interactive dynamic button that turn on and off brightness. Let me paste the code here, in case someone else is interested:

Script 1:

tell application "BetterTouchTool"
set currentBrightness to get_number_variable "BuiltInDisplayBrightness"
if (currentBrightness) is 0.0 then
return true
else
return false
end if
end tell

Script 2

tell application "BetterTouchTool"
set currentBrightness to get_number_variable "BuiltInDisplayBrightness"
if (currentBrightness) is 0.0 then
tell application "BetterTouchTool"
set_number_variable "BuiltInDisplayBrightness" to 0.5
end tell
else
tell application "BetterTouchTool"
set_number_variable "BuiltInDisplayBrightness" to 0
end tell
end if
end tell
3 Likes

Is there a list of predefined/built-in variables? I don’t see it in the documentation, but maybe I’m looking in the wrong place.

1 Like

I'm currently updating the docs (not yet done):

2 Likes

Hi @Andreas_Hegenberg

Sent a pm but figured question would be better served in discussion. Recent update fixed the slider for the brightness under big sur so it doesn't keep reset back to left (0.0 brightness reading). However, the dynamic variable "BuildInDisplayBrightness" still does not work properly and still resets to 0.0 right after setting/changing brightness.

Can you advise if there's a new variable for getting brightness value? Much appreciated.

Imprint | Privacy Policy