Run script ONLY on button click. (With Alt Color Regex)

I might be totally missing something but I find myself running scripts every 1-2 seconds just to create toggling button colours (which still feel a bit laggy at that refresh interval)

I know that running scripts ensures the buttons stay in sinc, but for something like say... Night Shift, which I rarely toggle and is hidden behind a ctrl key anyway it seems expensive to run a script every 2 seconds to check if the button should be in 0/1 state.

If this sort of script was run only when widget becomes visible & when interacted with it would save quite a many unnecessary script runs and would function much the same (possibly feel MORE responsive)

Unless there is another way to do this which I have not yet discovered?

If you set the repeat interval to 0, it will only run once (or when it becomes visible). You can then assign either the same or another script as an action to the Touch Bar trigger, the action gets triggered when you press the button. (Using the predefined action "Run Apple Script" )

Hey thanks for the reply, I saw you reply with similar else where but i got confused because:

This option

Does not appear for scripts which are added as actions rather than on the script widget, therefor I am unable to use this sort of script to change the button icon (Though I could very well be missing something obvious.)

There it will always use the regex from the main script. However I think for this to work the assigned apple script action must be the first action in the action sequence.

1 Like

OH PERFECT!

I might make that into a tutorial!

(Just for completing purposes,) here's how I resolved this:

At the end of the Apple Script of the assigned action I add an action to update the widget it belongs to. Get the UUID by right clicking the widget, and replace YOUR_UUID with yours.
Should also work as a second action to a predefined action :slightly_smiling_face:

delay 0.5
tell application "BetterTouchTool"
	refresh_widget "YOUR_UUID"
end tell

And if you don't want to wait for the widget to run the whole script you can use

	tell application "BetterTouchTool"
		update_touch_bar_widget "YOUR_UUID" text "TEXT_IF_NEEDED" icon_data "BASE64_CODE"
	end tell

to update the widget with a specific icon/text/…

1 Like
Imprint | Privacy Policy