Dynamic touch-bar button based on shell script output

Hello,

I would like to create a touch bar button that runs a shell script when it's pressed, and that will modify the button based on the results of the shell script. Similar to the json output on the shell script widget.
Basically what I want is a shell script that starts docker and runs a few containers, then when that's done I want to display the text "Running" with some docker running icon, and then when pressed again the script would to the inverse, it will stop the containers and kill docker, then change the button text to "Stopped" and the icon to some docker stopped icon.
Is it possible to do something like this today?

Thank you!

you can also return the json from a shell script widget, I’m currently not on my computer to check but it should be the same as for the apple Script widget

Yes, the shell script widget does take a json output. But that widget has no action on button pressed, ideally what I'd need is for that widget to have a "run script when button pressed" option, then I would be able to do what I want to do.

I think you can assign the predefined action "Run Shell Script /Task" and return something from that. I will be able to help tomorrow!

Oh that makes sense, assign an action to the widget and have that action return the json, I tried it and it works. I now just need to write the script.
In what format is the font_color value? I'm not familiar with 4 comma separated numbers for color.

Had the same question once :slightly_smiling_face:

I managed to achieve what I was looking for! :partying_face:

Basically, I created a Shell Script Widget and the script for this is in charge of checking docker to see if it's running, stopped or unhealthy (based on number of containers running) and based on that it will output the corresponding json to reflect the status. This script runs every few seconds so it keeps the button up to date. Then I assigned a shell script action and in here I have the script that will start, stop and heal docker. So when I press the button theses actions are triggered.

Imprint | Privacy Policy