Changing an Icon for a TouchBar button using the HTTP interface

I'm trying to update the icon on a TouchBar button. I'm running the latest Alpha (v2.601).

Looking at the docs here , I have figured out how to update the text of the button (using Python requests I found I had to do something funky with the escaping as it did not like using "+" for space rather than "%20"). For example:

curl '!%22%7D'

Trying the same thing with a POST does not work. (I also found that a trailing new line in the JSON caused things to abort). It's not documented that it would work, but trying a number of options.

My attempt to update the icon I tried updating the "BTTIconData" in the JSON data, and having the value as the Base64 value I pulled by right clicking and copying the JSON on a existing button. However when sending this, I get a Connection reset by peer error - probably because the URL is too long (about 40KB).

I then tried using the update_touch_bar_widget URL path (this is a button, not a widget I know, but was testing things), and set the icon_path to a PNG on disk - however I found this would always crash BTT (and not sure it would work anyway).

So my questions are:

  • Is there a correct way to be updating the icons of TouchBar buttons?
  • Am I correct in guessing there is a limit to the URL length?
  • Is there a way to POST longer sets of data?

Happy to provide any further code / examples if it will help.

I also considered using a Widget, but both the script widgets run the code at a regular interval, which is not what I'm after in this instance.


PS: In case others are doing the same, this is the code I'm using to post the correctly escaped URL parameters in Python Requests:

    payload = {"uuid": UUID, "json": data}
    params = urllib.parse.urlencode(payload, quote_via=urllib.parse.quote)
    d = requests.get("", params=params)

Arg sorry, you are right, I forgot to disable the limit.
This should now be fixed in v2.604

Ah and btw. maybe have a look here: this is a really cool project by @Worie that greatly simplifies stuff like this (not python but nodejs)

1 Like

Updated, and it worked! Perfect! Thanks again.

(PS: I'll check out that library you mentioned as well)

@sillyfrog If you ever need some help with the mentioned lib, feel free to ping me :slight_smile: