Allow scripts to be ran only once when a folder is opened or the TouchBar context changes.

This would be a useful addition to allow checks to happen when a folder is opened. Currently, one has to refresh a script every n seconds to refresh the contents of the folder, this is, however, indifferent if the state of the folder is not bound to be changed if the first check fails. Would be an incredibly useful addition that would save a lot of CPU processing.

You could try using a button to open the group and attach an additional script action, which could trigger the widgets you need to be activated via UUID

Hey @dnnsmnstrr, thanks for the reply. I've done that in portions of my layout where it was fit, but in some instances -- like changing state between apps -- this is not possible.

What I mean by 'changing state between apps' is when I scroll to Terminal I would like BetterTouchTool to update the Touch Bar state, and therefore icons (as it does, ofc), and at the same time run a script once. Hope that makes sense!

Maybe you can put a script widget in the each app's trigger list, that only gets run when it becomes visible and update the other widgets from there. I'm not really sure what you would need this for though

I did not think of that! That is indeed a good idea that I'll give it a shot.

In essence, I am writing a complete Touch Bar replacement and I have a script that checks to see if there is any updates available to the preset. The update-checking part I've been able to do without a hitch, but now the issue is the actual execution of the script. Right now I have a bootleg version:

  1. BetterTouchTool context is opened.
  2. Bash script runs every n seconds.
    • Bash script returns nothing if no update. No button is created since buttons can't have empty names.
    • Bash script returns "Update Available!" if there is an update. Button gets generated.

I would like to simply replace that with:

  1. BetterTouchTool context is opened.
  2. Script is ran once and does its thing.
  3. Script modifies the context of BetterTouchTool.

The difference is minimal, but it will save a lot of CPU power. Your idea, however, might just be my solution.

I gave it a try, and sad to report it did not work. Since the script would have to make this new button unseen (since I do not wish to have extra buttons), once the logic runs, there is no way to reset it back to normal.

A simple "run script once" toggle would be the simplest solution, imo.

It might be possible to „hide“ the button by playing around with its width - negative values also work.
If you then set the refresh rate to a very long time and enable refreshing when the widget becomes visible, you should basically have the behavior you want.

I thought of that as well but unfortunately the "Execute script every" does not: execute and then wait. It rather does: wait, then execute. Which means setting a timer of (lets say) 60 seconds means the script does not get ran for 60 seconds once the layout changes -- this tactic would work if it the script ran, and then waited.