TouchBar Pomodoro - Keeping stuff from other apps in our Touch Bar!

Hi,
So I've recently started using BTT GodenChaos for my TouchBar experience on Mac.
I found this really cool little Pomodoro app that essentially creates an pomodoro timer in your TouchBar. I wanted to find a way to keep it running or create a widget that allows me to keep touch-bar widgets / icons from applications.

I'm trying to get this Pomodoro Tomato Bar widget to work with @goldenchaos and think it will be a great extension to the program. If I'm able to figure out how to get this working I'm more than happy to create a tutorial for programming novices like myself.

I take the challenge to do a small BTT series of script in order to do something with that idea.
Here is the preset


(But i doubt that the activation group that I use is shared so you might need to create it.

Let me explain the idea (such that it works as a tutorial as well)

In the "all app" section of the touchbar, I have created one button:


If I press the button, I have configure an applescript opening an invite

Which allows to setup the time for the timer.
The associated applescript is here


set theResponse to display dialog "Enter number of minuts for the timer" default answer "3" with icon note buttons {"Cancel", "Continue"} default button "Continue"
if button returned of theResponse is not "Continue" then
	return
else
	set nb_min to text returned of theResponse as integer
end if

set nb_sec to nb_min * 60

tell application "BetterTouchTool"
	set_persistent_string_variable "customVariable1" to "running"  shared_secret ""
	set_persistent_number_variable "countdown" to nb_sec  shared_secret ""
end tell

Here you can see that I setup two variable of BTT, one call customVariable1 (will explain why later)
and the second one, the number of second of the timer.

The reason of the variable customVariable1 is that you can trigger activationgroup based on the value of that variable (see image)


This group has a single button (which stop the timer if pressed).

Additionally, I have configure a trigger in the "named and other triggers" section.
I setup a trigger that start to run an applescript as soon as the activation group is activated.

tell application "BetterTouchTool"
	set nb_sec to get_number_variable ("countdown") shared_secret ""
	repeat while nb_sec is not 0
		set nb_min to nb_sec div 60
		set nb_sec_add to nb_sec mod 60 as integer
		update_trigger "00ED63F8-DA13-4C43-BAC4-AB7D5A032C3C" json "{\"BTTTouchBarButtonName\" : \"" & nb_min & "m" & nb_sec_add & "s\"}" shared_secret ""
		delay 1
		set nb_sec to nb_sec - 1
	end repeat
	set_persistent_number_variable ("countdown") to 0 shared_secret ""
	set_persistent_string_variable ("customVariable1") to "not running" shared_secret ""
	trigger_named_async_without_response "stop_countdown" shared_secret ""
	
end tell

So this script

  1. Update the name of the button (with the remaining time) every second
  2. called a named trigger when we reach the end of the countdown
  3. deactivate the conditional group at the end of the countdown (by resetting the variable)

The named_trigger allows to setup any BTT action. For the demo here, this is just showing a HUD on the screen written stop (but you have all the options of BTT).

This is more a proof of concept (and me having fun and experimenting some idea) than a full solution.
This has therefore many limitation (only one count-down, no reset of the timer, ...)
But this is something that we can discuss and that everyone should be able to customize to his own needs.

The link to the preset appears to be invalid.

I second that. this would be a nice preset to have