Can a script widget's alternate regex effect be forcibly updated?

I have a widget with an alternate color that I'd like to forcibly activate to prevent having to constantly check the value of the variable (I'm checking SystemDoNotDisturbState).

I checked the forums and so far have only found this related discussion, which sounds like the same issue I'm seeing. However, the doc page provided 404s and I don't see a direct way to approach the issue on the new Applescript docs page.

I can find ways to perform update_trigger, but the issue I see with that method is that I can't retain both the original color and background color on the trigger itself. So any future updates to DND would not synchronize the color properly, I believe.

I also see update_touch_bar_widget that might work for this, but even when I try to set all of the params, the button just disappears and returns in a few seconds. It's also unwieldy to set the icon_data param via script.

Any advice is appreciated.

The easiest way would probably be to use the refresh_widget function. It will execute the scripts assigned to a widget and update its content.

If you set the standard repeat rate of the script to 0 (never), and only update it using the refresh_widget function it should achieve the desired effect.

1 Like

Thank you for the help, @Andreas_Hegenberg. I had tried refresh_widget yesterday via Applescript and it does not throw any errors, but the widget still seems to operate on its own update schedule (currently 10s). I tried it again today and played with async vs blocking, but the same behavior occurs.

The only thing I can guess is that my trigger isn't set up to properly calculate itself. Would it be helpful to copy the trigger here?

Yes! Having the trigger would help a lot. You can just cmd+c in BTT and cmd+v the resulting json here.

"BTTWidgetName" : "Do Not Disturb",
"BTTTriggerType" : 639,
"BTTTriggerTypeDescription" : "Apple Script \/ JavaScript Widget",
"BTTTriggerClass" : "BTTTriggerTypeTouchBar",
"BTTPredefinedActionType" : 200,
"BTTPredefinedActionName" : "Toggle Do Not Disturb On\/Off",
"BTTEnabled2" : 1,
"BTTRepeatDelay" : 0,
"BTTUUID" : "2B6E1445-0C88-4E60-8820-9E1CD391384B",
"BTTNotesInsteadOfDescription" : 0,
"BTTEnabled" : 1,
"BTTModifierMode" : 0,
"BTTOrder" : 7,
"BTTDisplayOrder" : 0,
"BTTMergeIntoTouchBarGroups" : 0,
"BTTTriggerConfig" : {
  "BTTTouchBarItemPadding" : 0,
  "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
  "BTTTouchBarItemPlacement" : 2,
  "BTTTouchBarAppleScriptStringRunOnInit" : true,
  "BTTTouchBarAlwaysShowButton" : false,
  "BTTTouchBarButtonFixedWidthCutOff" : 1,
  "BTTScriptType" : 0,
  "BTTTouchBarScriptUpdateInterval" : 10,
  "BTTTouchBarButtonWidth" : 100,
  "BTTTouchBarItemIconHeight" : 22,
  "BTTTouchBarButtonTextAlignment" : 0,
  "BTTTouchBarAlternateBackgroundColor" : "127.720540, 132.903021, 235.354066, 255.000000",
  "BTTTouchBarAppleScriptUsePath" : 0,
  "BTTTBWidgetWidth" : 400,
  "BTTTouchBarColorRegex" : "1",
  "BTTTouchBarItemIconWidth" : 22,
  "BTTTouchBarLongPressActionName" : "",
  "BTTTouchBarButtonName" : "Do Not Disturb",
  "BTTTouchBarButtonFontSize" : 15,
  "BTTTouchBarIconTextOffset" : 5,
  "BTTTouchBarOnlyShowIcon" : true,
  "BTTTouchBarFreeSpaceAfterButton" : 10,
  "BTTTouchBarAppleScriptString" : "tell application \"BetterTouchTool\"\n    return get_number_variable \"SystemDoNotDisturbState\"\nend tell"
Imprint | Privacy Policy