Setting "icon only" in JSON return string doesn't work.

MacOS Mojave
BTT version 2.660

I have a touch bar button that shows an icon and a number (the number is obtained from a script that runs periodically).

I would like the button to show just the icon if the number is 0 and icon plus text if the number is > 0.

I've got it returning this for the zero case:

"{\"text\":\"[0]\", \"background_color\":\"0,0,0,255\", \"font_color\":\"235,235,235,255\", \"BTTTriggerConfig\" : {\"BTTTouchBarOnlyShowIcon\" : true}}"

but the text still shows up, as if it's ignoring the BTTTouchBarOnlyShowIcon setting. Everything else is fine, the text shows correctly and the colours are correct.

Is this:

a) deliberate
b) a bug
c) me getting the format wrong?

You can not return a trigger config here. However I think returning an empty string should work.

Only these things can be returned here:

Alternatively you'd need to use the update_trigger function ( ), where you can also change the BTTTriggerConfig

Yeah. Returning an empty string isn't what I want, since it hides the entire button. I wanted to avoid using update_trigger, since it relies on the UUID, so isn't generalisable, but it looks like that's what I'll have to do.

Curious. When I add the update_trigger code, the whole button disappears again.

Here's the relevant handler:

on set_self_icon_only(onoff)
	set self_uuid to "946E4923-1DEF-400E-BD3E-EB10B928C532"
	set icon_only_json to ¬
		"{\"BTTTriggerConfig\" : {" & ¬
		"\"BTTTouchBarOnlyShowIcon\" : " & (onoff as text) & ¬
	tell application "BetterTouchTool" to ¬
		update_trigger self_uuid json icon_only_json
end set_self_icon_only

When I look, the check box has been updated, the widget is still marked as visible, and the script is returning some text.

Here's the bit that returns the string to the widget:

on construct_retval(num)
	set retval to ""
	set the_text to "\"text\":\"[" & (num as text) & "]\""
	set the_bg_col to first item of default_calendar_colours
	set the_fg_col to second item of default_calendar_colours

	set retval to "{" & the_text
	set retval to retval & ", \"background_color\":\"" & the_bg_col & "\""
	set retval to retval & ", \"font_color\":\"" & the_fg_col & "\""
	set retval to retval & "}"
	--set_self_icon_only(num is 0)
	return retval
end construct_retval

Any thoughts?

Found the problem. It's related to something else I found, but I made a workaround for it. The workaround also works here, so I think it's related.

I have a script that enables/disables groups of widgets (I was going to post the code here once I've I've got it ironed out). This code allows me to have sets of widgets in the global section conditionally visible depending on which app is at the front, without using groups. (Groups pose particular problems in that, once open, they stay there, plus you have to duplicate the widgets that you want always visible.)

What my code does is to recognise when the front app has changed, and make the previous app's special widget set invisible, and the new app's set visible.

What I found was the the last widget of the new group didn't become visible unless I did something to "kick" the touchbar (e.g. I have the app switcher on the CMD key, so I press command, appswitcher appears, release command and the previously invisible widget is now there).

I made a workaround by always enabling a special invisible widget (it consists of a script that is just return "", run when it it becomes visible). This gives a kick to the touchbar and all my real widgets show up.

By adding the workaround code to my set_self_icon_only handler, the widget now appears correctly.