Hi there!
Alert: I have absolutely no idea how to make scripts and run terminal commands or anything, I just research stuff until I somehow manage to make something that works.
I created a touch bar button - when pressed, it changes the audio output - goes to the next one. The button's text displays the current output. The only way I could do it was to download Homebrew and install Switchaudio-osx and then make Bettertouchtool execute the commands.
I set it as "Shell Script / Task Widget". In the "Trigger Name" -> "Widget Specific" section I set it up to run a homebrew command: /opt/homebrew/bin/SwitchAudioSource -c
"Actions Executed On Trigger": Execute Shell Script / Task, the script is: /opt/homebrew/bin/SwitchAudioSource -n
To my surprise, it works perfectly! The button shows a beautiful speaker icon and a name of the current audio output. When pressed, it cycles to the next output and the text changes to the output name (actually, it has a minimal delay - for like 0.5 second before showing the output name it shows "Audio output" , but whatever it doesn't bother me that much).
My joy lasted a few hours and then it stopped working. The button text showed "Couldn't P..." (i don't know what exactly, because it didn't fit the button's width) and did nothing when pressed. Then I opened terminal to check if the commands still worked and it said that I'm dumb and that "forkpty: Resource temporarily unavailable".
The widget and terminal start working again after restarting the computer or just logging out and in again. All runs fine for a few hours and it stops again.
I did some research and apparently the terminal error has something to do with too many processes running at the same time, idk. My idea is that I have no idea what I do and there's a better way to achieve what I need. Maybe "Execute script every x seconds" is not exactly what I want? Does it literary run the same script every few seconds until my macbook gets mad and says that it's enough?
I would be greatful for any help and sorry again for being noobish and ignorant.