Keyboard Backlight Brightness Touchbar Slider

touch-bar
keyboard

#1

After a ton of hacking, I finally figured out a way to implement a slider for keyboard backlight illumination that is roughly consistent with the out if the box volume and screen brightness slider widgets.

The implementation takes the form of a custom applescript slider that triggers two other (hidden) buttons that take advantage of the single step up/down in backlight brightness. The slider will first set the keyboard brightness and slider position to 0, and then poll on slider movement to see if the slider is "ahead" or "behind" of the brightness we set under the hood with our buttons, step by step.

First you'll need to create two simple Keyboard Illumination Up/Down buttons. One of each. Make sure they work, but then uncheck their visible checkboxes as they wont be needed when the slider is in place.

Right click each of them and click "Copy UUID (for use with Applescript)" Toss them in a text doc or something for quick reference in a moment.

Create a custom applescript slider. The initial applescript will just dim the brightness all the way (16 times is the max) and set the slider value to 0, to harmonize the brightness and slider values. The applescript to enter under the "custom configuration" option of the slider is:

tell application "BetterTouchTool"
set_number_variable "current" to 0
repeat 16 times
	execute_assigned_actions_for_trigger "AE1FCD12-E8A2-418C-810D-838951526320"
end repeat
end tell
return 0.0

Replace the UUID in this code with the uuid of the button that DIMS the backlight by one step.

Set the predefined action to "Run Applescript (async)", and enter the following applescript.

on bttWidgetSliderMoved(sliderValue)
tell application "BetterTouchTool"
	set slider to round (sliderValue * 16)
	set current to round (get_number_variable "current")
	if slider > current then
		set num to slider - current
		repeat num times
			execute_assigned_actions_for_trigger "D9DB3A67-E6A0-49B3-8433-CB0D7540D08C"
		end repeat
		set_number_variable "current" to current + num
	else if slider < current then
		set num to current - slider
		repeat num times
			execute_assigned_actions_for_trigger "AE1FCD12-E8A2-418C-810D-838951526320"
		end repeat
		set_number_variable "current" to current - num
	end if
end tell
end bttWidgetSliderMoved

Again, replace the second uuid listed with the uuid of the button that dims the backlight, but replace the first uuid listed with the one that raises it. you may also choose to use some globally defined ids, but i didn't.

This should give you a roughly consistent keyboard backlight slider. You can also chose to have the default value be something other than 0 / no brightness by editing the initial configuration. Reply with any questions or clarifications and I'm happy to reply with guidance if possible, and all feedback is of course appreciated.


Keyboard Brightness Slider Widget?