"Brightness Up (Small Step)" and "Brightness Down (Small Step)"

Hi!

It would be nice to have a feature similar to the "Volume Up (Small Step)" and "Volume Down (Small Step)" Actions.

Thanks.

You can do this with AppleScript quite easily:

use prefs : application "System Preferences"
use sys : application "System Events"

property process : a reference to application process "System Preferences"
property window : a reference to window 1 of my process
property pane : a reference to pane id "com.apple.preference.displays"
property anchor : a reference to anchor "displaysDisplayTab" of my pane
property UI element : a reference to sliders of groups of tab groups of my window
property slider : a reference to (my UI element whose description = "brightness")

contents of my anchor = (reveal my anchor)
if the result = false then return

with timeout of 60 seconds
	repeat until my slider exists
		delay 0.5
	end repeat
end timeout

set [[[S]]] to the contents of my slider
tell S to set its value to (its value) + 0.05

quit prefs

The + 0.05 on the penultimate line is where the step change in brightness is implemented. + indicates an increase in brightness, and you can change this to - for a decrease.

The value for brightness has a minimum of 0.0 and a maximum of 1.0, but there’s no need to worry about going outside of this range as it will be capped automatically at both ends, and effectively not do anything when trying to go beyond those values.

1 Like

Hi @CJK,

Thank you for your help. Unfortunately it doesn't seem to work well in my situation; I'll explain.

I have a Touch Bar, and I currently have it setup for Three Finger Swipe Right (under Widgets) to do "Brightness Up". With this, you can do "Repeats after position has changed %". Therefore, I can go from 0% brightness to up to 100% brightness in one swipe on my Touch Bar.

This works perfectly with the "Volume Up (Small Step)" Action, as I get even finer control, rather than jumping full blocks.

Do you know how I could achieve this with brightness?

Thanks.

Can you explain what difficulties you're having implementing or adapting my script to do what you're saying ? I don't have a touchbar so can't test that particular aspect of a system's hardware.

The script I've written, when executed, will increase the display brightness by a step of 0.05 (on a scale of 0 to 1), which is the equivalent of 5% on a scale of 0% to 100%.

The script currently doesn't return any value after it terminates.

If I were to create a touch pad action on my laptop with a Three Finger Swipe Right trigger, I would attach a Run AppleScript (or similarly named) action to it that executes the above script. Then, each time I swipe right with three fingers, the display will brighten by 5%.

I presume the process is similar with the touch bar. If it's different, you'll need to do your best to explain how it's different and what adpatations would be needed in the script to make it viable for your use case. I will be happy to make those changes for you.

1 Like

@CJK

To make things easier for both of us, I have setup a Keyboard shortcut (instead of Touch Bar). I set the "Trigger Predefined Action" to "Run AppleScript" and pasted the script you wrote above. Now, when I do that keyboard shortcut, nothing happens. I have also disabled and enabled the "Run in Background" option; same results.

I am also running macOS High Sierra Version 10.13.6 (17G65)

Thanks.

Please try, for now, and run the script using Script Editor. It's located in the "Utilities" folder of your "Applications" folder, and you can copy and paste the script into a new file, then press the button with the Play symbol to execute the script.

If you've not used Script Editor before, the system will ask you to authorise it to control your system, which will take you System Preferences where you can tick the checkbox in the list of applications next to Script Editor. It may need to do the same for System Events. Then run the script again.

This will confirm whether the problem is with the script itself, or with something that's happening in your BetterTouchTool that's getting in the way.

Just to put my own mind at ease, I went a created a keyboard shortcut in the manner you described. It worked as expected for me. Here are screenshots of my BTT trigger and action set up:


1 Like

Also, can you tell me what country you're from, and/or what language your system uses if it's not English ?

1 Like

@CJK,

If you've not used Script Editor before, the system will ask you to authorise it to control your system, which will take you System Preferences where you can tick the checkbox in the list of applications next to Script Editor . It may need to do the same for System Events . Then run the script again.

It now works as expected after allowing Script Editor to control my computer.

Thank you!

@CJK,

When setting a widget/gesture on the Touch Bar, a Hint shows up:

Hint (Advanced):
If you assign the "Run Apple Script In Background" action, BTT will automatically pass the moved percentage to the script. This can be used in Apple Script like this:

on bttWidgetSliderMoved(percentageMoved)
	#example to change system volume:
	set volume output volume percentageMoved * 100
end bttWidgetSliderMoved

This works fine with audio/volume, but do you know how I could do this with the brightness? It seems a better solution when using the Touch Bar.

Thanks.

Edit: forgot to mention, I tried doing "brightness" instead of volume, but that doesn't work.

Looking at that hint snippet, it basically looks as if it's a handler that's called by BTT in response to the slider being moved, and it sends the new value of the slider (which, judging by the volume example, is an absolute, not relative, value) to the handler as a parameter (which they've named percentageMoved, though I would personally rename it for being misleading, as it implies a relative value).

If my assessment is correct, then you should be able to just put the contents of the run handler from my script into this BTT handler called bttWidgetSliderMoved(), and use its parameter to set the value of the variable S.

If you're wondering where the run handler is in my script, it's not visible, and is referred to as an implicit handler. But that's a side-note; the contents of my run handler includes every line of code starting with contents of my anchor through to the end.

So, basically, my guess is that the script should look like this (I also made a couple of other syntactical tweaks):

use prefs : application "System Preferences"
use sys : application "System Events"

property process : a reference to application process "System Preferences"
property window : a reference to window 1 of my process
property pane : a reference to pane id "com.apple.preference.displays"
property anchor : a reference to anchor "displaysDisplayTab" of my pane
property UI element : a reference to slider 1 of groups of tab groups of my window
property slider : a reference to (my UI element whose description = "brightness")

on bttWidgetSliderMoved(x)
	local x
	
	reveal my anchor
	
	try
		with timeout of 60 seconds
			repeat until my slider exists
				delay 0.5
			end repeat
		end timeout
		
		set the value of my slider to x
	end try
	
	quit prefs
end bttWidgetSliderMoved

See how you get on with that.

Small Step actions for brightness will be available with the next update (alpha later today)

@Andreas_Hegenberg,

Looking forward to it; thank you very much!

The alpha is now available :slight_smile:

1 Like