I'm trying to update the icon on a TouchBar button. I'm running the latest Alpha (v2.601).
Looking at the docs here https://docs.bettertouchtool.net/docs/webserver.html , 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 'http://127.0.0.1:12345/update_trigger/?uuid=48787D1B-3569-4031-98DC-747CBA863EF7&json=%7B%22BTTTouchBarButtonName%22%20:%20%22Hepy!%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.
Thanks!
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("http://127.0.0.1:12345/update_trigger/", params=params)