Help with writing a widget for BTT

I have a widget that check if file exists and returns true or false.

I want to make TouchBar only show an icon if it returns false. Otherwise show nothing. It doesn’t work for me for some reason.

Is it possible to do?

I think you should not put the regex in quotes.
It works here if I just enter false

Ah sorry, I didn't completely read the middle part :slight_smile:

To hide a widget you need to return an empty string.

Thank you, it works.

I have a question about performance of this. Is it okay to run this kind of action every 9 seconds or it will cost me some battery time?

The other 3 TouchBar widgets I use are these:

This is definitely ok. (Look at other presets here in the forum which run many scripts per second).

The scripts you use are very small and running them every few seconds is definitely not an issue.

1 Like

I want to make sure I get it right but if a Widget is not marked not visible like so:

The code is not going to be ran by BTT in background right?

Also is it okay to run the below code every 1 second? I want to emulate menu bar reactivity but am afraid I will burn the battery this way. I feel like ideally it would not have to be me querying to ask what keyboard layout I have every 1 second but BTT reacting on keyboard layout switching and making the call only then, if that's possible.

If you're worried about how much energy BTT is using, have a look in the Energy tab of Activity Monitor. I have a lot of scripts goin (many every 1 second) and my energy impact is usually around 7.
You could compare the impact with the script running and not running to see if makes any difference.