Touchbar Script - Toggle-able String

I am working on a iTunes Now Playing/Play/Pause touchbar widget, and I would love it if, when nothing is playing in iTunes, the Touchbar button would collapse to the icon. The only way I've figured out how to get close to this behavior is to return a space (" ") from my script. This clears the text on the button, but leaves some space to the left of the icon. I've tried returning an empty string (""), a zero-width space (U+200B), or just simply returning without a value. Nothing gets me quite where I want to be...

Anyone have any advice (or a pointer to the obvious thing I am missing)?

Thanks!

I guess you could run update_touchbar_widget from AppleScript or webserver and set BTTTouchBarOnlyShowIcon to 1.

The structure of the payload should be like this, for example :

{
  "BTTTouchBarButtonName" : "Apple",
  "BTTTriggerType" : 629,
  "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
  "BTTPredefinedActionType" : 125,
  "BTTPredefinedActionName" : "Show Menubar in Context Menu",
  "BTTEnabled2" : 1,
  "BTTUUID" : "5AF1A13C-9C35-4F47-A5EE-93AE1DF4D653",
  "BTTEnabled" : 1,
  "BTTRequiredModifierKeys" : 524288,
  "BTTOrder" : 10,
  "BTTIconData" : "REALLY LONG, BASE64 encoded image",
  "BTTTriggerConfig" : {
    "BTTTouchBarItemIconHeight" : 20,
    "BTTTouchBarItemIconWidth" : 20,
    "BTTTouchBarItemPlacement" : 1,
    "BTTTouchBarItemPadding" : 0,
    "BTTTouchBarFreeSpaceAfterButton" : "5.000000",
    "BTTTouchBarButtonColor" : "0.000000, 0.000000, 0.000000, 255.000000",
    "BTTTouchBarAlwaysShowButton" : "0",
    "BTTTouchBarAlternateBackgroundColor" : "0.000000, 0.000000, 0.000000, 0.000000",
    "BTTTouchBarOnlyShowIcon" : 1
  }
}

So, you should toggle JSON['BTTTriggerConfig']['BTTTouchBarOnlyShowIcon'] value :slight_smile:

Thanks for the pointers! While I believe I had to use update_trigger (as opposed to update_touch_bar_widget (which afaict, doesn't accept JSON)), this was enough to get me over the finish line. My finished method looks like:

on toggleIconOnly(inputValue)
	tell application "BetterTouchTool"
		update_trigger "C9E548FB-B382-4BBB-A9CA-36F274A51A52" json ("{
            \"BTTUUID\" : \"C9E548FB-B382-4BBB-A9CA-36F274A51A52\",
            \"BTTTriggerConfig\" : {
                \"BTTTouchBarOnlyShowIcon\" : " & inputValue & "
            }
        }")
	end tell
end toggleIconOnly

oh yeah, right - I meant update_trigger :slight_smile: I'm glad you found your way through!

1 Like