`update_stream_deck_widget` example code reliably crashes BTT

I'm trying to test out a new way of doing my "show the current audio source" Stream Deck button that's more reliable (and doesn't require running a script every few seconds), and as part of that, I'm trying to use the update_stream_deck_widget method in a "Run Real JavaScript" action on a named trigger.

Using the example code causes BTT (alpha 4.053 (2272)) to crash whenever I press the "Run Script" button in the BTT action configuration editor. I've made two minor changes, but these don't seem to affect whether it crashes or not:

  1. I set the uuid as a variable, because long-term, I probably will end up hitting a couple of methods against the same widget, and also it reads cleaner
  2. I removed the comma after the last line of the widgetConfig JSON, since JSON can be finicky about unnecessary trailing commas (I tried it both ways and had hoped that removing the comma would be an easy fix, but alas, no).
 (async ()=> {

   let widgetConfig = {
     text: "some new title!",
     BTTStreamDeckBackgroundColor: "200,100,100,255",
     BTTStreamDeckSFSymbolName : "bitcoinsign.circle.fill"
   };

   let uuid = 'B1F1D9EA-0016-48EA-A312-F1F8FD4E6CA2';

   callBTT('update_stream_deck_widget', {uuid: uuid, json: widgetConfig}); 
   
   returnToBTT(JSON.stringify(widgetConfig));
 })();

I've definitely noticed that BTT / Stream Deck can be SUPER finicky about the precise JSON being returned / sent to the button / etc, and that the failure state is crashing (rather than some kind of alert), so I'm GUESSING that there's something wonky in the JSON being passed (or in processing that JSON) but I'm not really sure how to further diagnose it. I've tried using JSON.stringify, escaping quotes, etc., and not really found anything that works (sending stringified JSON doesn't cause a crash, but it also doesn't seem to actually DO anything).

I've tested using a "regular" Stream Deck trigger, a Run Apple Script trigger, and a Shell Script / Task trigger as targets; all of them fail in the same way (a crash).

Attached is a crash report (added .crash to the end because .ips isn't an allowed upload format)

Any thoughts?

BetterTouchTool-2023-03-03-123557.ips.crash (26.9 KB)

Any chance you've had chance to look at this?

Sorry not yet.
However the callBTT line should be changed:

   callBTT('update_stream_deck_widget', {uuid: uuid, json: JSON.stringify(widgetConfig)}); 

BTT only accepts a json string as the parameter, not the Java Script object (widgetConfig). Thus it needs to be stringified first.

I thought that might be the case, and I have tested that; BTT no longer crashes, but it ALSO doesn't actually update the button. Is there a real-time log I can watch to see if there's some error being thrown that I just can't see?

(also, this documentation should probably be updated, as it doesn't include the stringify step)

1 Like

Yep will update the docs!

The rest of your script looks good, I just tried it and it works fine here:

(async ()=> {

   let widgetConfig = {
     text: "some new title!",
     BTTStreamDeckBackgroundColor: "200,100,100,255",
     BTTStreamDeckSFSymbolName : "bitcoinsign.circle.fill"
   };

   let uuid = '222F2CFA-C0B8-4130-9B4C-58BCA73A2511';

   callBTT('update_stream_deck_widget', {uuid: uuid, json: JSON.stringify(widgetConfig)}); 
   
   returnToBTT(JSON.stringify(widgetConfig));
 })();

Are you sure the UUID is correct?

Positive. Are there any restrictions on the types of Stream Deck widgets that can be updated, or on whether the "use notes instead of description" box should be checked, or anything like that?

The update_stream_deck_widget is only for script widgets, maybe that's the problem

Does it matter if it's an AppleScript widget or a shell script widget?

Also, it'd be pretty cool to be able to update non-script widget buttons, 'cause I don't actually need the button I'm trying to update to be periodically running a script (in this particular case)

1 Like

Apple Script or Shell Script doesn't matter.

If you want to update a non-script widget, that's possible, but only by permanently changing the values with the update_trigger function

Gotcha. I may try that. I'm still having no luck with my button actually updating, regardless of whether I use an AppleScript or Shell Script trigger. It seems very weird.

1 Like