simple, efficient timer widget

A timer widget for the touch bar

I made a simple timer widget for the touch bar that actually consists of just one widget. When pressed, It asks for the time via a dialog popup and starts the countdown. If pressed again, it cancels the countdown. When finished, it blinks red/black a few times. The widget only refreshes regularly while the timer is actually running, so the power usage should be really low i think.

05
46
20

feel free to leave feedback!

download link:
https://share.folivora.ai/sharedPreset/53545d61-1a3a-4f54-ae6f-e2954cec4ff9

Note that in order for the widget to work I think you have to copy the UUID of the widget by right clicking on it and replace the UUID in the script (it appears several times).

I'm not sure whether importing the widget from the download works, see the comments. Alternatively, create a widget on your own and paste the scripts below. I would suggest then setting 255,38,0 as alternative background color activating when the return value is "00:00", so the widget stays red after blinking when the time is up. Also you can set the "Execute every X seconds" value much higher than default, as the widget gets refreshed by the script when necessary. I used the "Alarm" icon from this icon pack: [v3 Update] Native Apple Touch Bar Icon Pack for BTT

Widget JSON:

{
  "BTTWidgetName" : "Timer",
  "BTTTriggerType" : 639,
  "BTTTriggerTypeDescription" : "Apple Script Widget",
  "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
  "BTTPredefinedActionType" : 195,
  "BTTPredefinedActionName" : "Apple Script starten (asynchron im Hintergrund)",
  "BTTInlineAppleScript" : "tell application \"BetterTouchTool\"\r\t\r\tset remainingSeconds to get_number_variable \"remainingSeconds\"\r\t\r\tif (remainingSeconds is equal to 99999) or (remainingSeconds is equal to missing value) then --timer is not running and should be started\r\t\t\r\t\t--ask for the duration via a dialog popup\r\t\tset dialogAnswer to display dialog \"Please set timer using HH:MM:SS (max. 24 hours):\" default answer \"00:00:05\" --edit this to change the default time\r\t\tset answer to text returned of dialogAnswer\r\t\tset answerHours to text 1 thru 2 of answer as text\r\t\tset answerMinutes to text 4 thru 5 of answer as text\r\t\tset answerSeconds to text 7 thru 8 of answer as text\r\t\t\r\t\tset totalSeconds to (answerHours * 3600) + (answerMinutes * 60) + answerSeconds\r\t\t\r\t\tset_number_variable \"remainingSeconds\" to 99998\r\t\t\r\t\trepeat totalSeconds times --count\r\t\t\tif (get_number_variable \"remainingSeconds\") ≠ 99999 then -- if the variable is 99999, that means the timer was pressed again and should be stopped\r\t\t\t\tset totalSeconds to (totalSeconds - 1)\r\t\t\t\tset_number_variable \"remainingSeconds\" to totalSeconds\r\t\t\t\trefresh_widget \"2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10\"\r\t\t\t\tdelay 1\r\t\t\tend if\r\t\tend repeat\r\t\t\r\t\tif (get_number_variable \"remainingSeconds\") ≠ 99999 then\r\t\t\trepeat 10 times --blink to signal that the time is up\r\t\t\t\tupdate_touch_bar_widget \"2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10\" background_color \"0,0,0,0\"\r\t\t\t\tdelay 0.5\r\t\t\t\tupdate_touch_bar_widget \"2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10\" background_color \"255,38,0,255\"\r\t\t\t\tdelay 0.5\r\t\t\tend repeat\r\t\tend if\r\t\t\r\telse --timer is running and should be stopped\r\t\tset_number_variable \"remainingSeconds\" to 99999\r\t\trefresh_widget \"2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10\"\r\tend if\r\t\rend tell",
  "BTTEnabled2" : 1,
  "BTTUUID" : "2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10",
  "BTTEnabled" : 1,
  "BTTModifierMode" : 0,
  "BTTOrder" : 91,
  "BTTDisplayOrder" : 0,
  "BTTMergeIntoTouchBarGroups" : 0,
  "BTTIconData" : "TU0AKgAAE7gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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riptType" : 0,
    "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
    "BTTTouchBarColorRegex" : "00:00",
    "BTTTouchBarItemIconWidth" : 30,
    "BTTTouchBarItemPlacement" : 0,
    "BTTTouchBarAlternateBackgroundColor" : "255.000000, 38.028511, 0.000000, 255.000000",
    "BTTTouchBarButtonCornerRadius" : 6,
    "BTTTouchBarScriptUpdateInterval" : 60,
    "BTTTouchBarAppleScriptString" : "tell application \"BetterTouchTool\"\r\tset remainingSeconds to get_number_variable \"remainingSeconds\"\r\t\r\tif (remainingSeconds is equal to 99999) or (remainingSeconds is equal to missing value) then -- the timer is not running\r\t\treturn \"timer\"\r\telse -- the timer is running or is finished\r\t\t\r\t\t--create return text\r\t\tset outputSeconds to ((remainingSeconds mod 3600) mod 60) as integer\r\t\tset outputMinutes to (((remainingSeconds - outputSeconds) mod 3600) \/ 60) as integer\r\t\tset outputHours to ((remainingSeconds - outputMinutes * 60 - outputSeconds) \/ 3600) as integer\r\t\tif length of (outputSeconds as string) is equal to 1 then\r\t\t\tset outputSeconds to \"0\" & outputSeconds as string\r\t\tend if\r\t\tif length of (outputMinutes as string) is equal to 1 then\r\t\t\tset outputMinutes to \"0\" & outputMinutes as string\r\t\tend if\r\t\t\r\t\t--return text\r\t\tif outputHours is greater than 0 then\r\t\t\treturn (outputHours & \":\" & outputMinutes & \":\" & outputSeconds) as string\r\t\telse\r\t\t\treturn (outputMinutes & \":\" & outputSeconds) as string\r\t\tend if\r\tend if\rend tell",
    "BTTTouchBarAppleScriptStringRunOnInit" : false,
    "BTTTouchBarButtonName" : "Timer",
    "BTTTouchBarAppleScriptUsePath" : 0,
    "BTTTouchBarFreeSpaceAfterButton" : 5,
    "BTTTouchBarItemIconHeight" : 30,
    "BTTTouchBarItemPadding" : 0
  }
}

the script for the return value:

tell application "BetterTouchTool"
	set remainingSeconds to get_number_variable "remainingSeconds"
	
	if (remainingSeconds is equal to 99999) or (remainingSeconds is equal to missing value) then -- the timer is not running
		return "timer"
	else -- the timer is running or is finished
		
		--create return text
		set outputSeconds to ((remainingSeconds mod 3600) mod 60) as integer
		set outputMinutes to (((remainingSeconds - outputSeconds) mod 3600) / 60) as integer
		set outputHours to ((remainingSeconds - outputMinutes * 60 - outputSeconds) / 3600) as integer
		if length of (outputSeconds as string) is equal to 1 then
			set outputSeconds to "0" & outputSeconds as string
		end if
		if length of (outputMinutes as string) is equal to 1 then
			set outputMinutes to "0" & outputMinutes as string
		end if
		
		--return text
		if outputHours is greater than 0 then
			return (outputHours & ":" & outputMinutes & ":" & outputSeconds) as string
		else
			return (outputMinutes & ":" & outputSeconds) as string
		end if
	end if
end tell

the script that is executed when the widget is pressed:

tell application "BetterTouchTool"
	
	set remainingSeconds to get_number_variable "remainingSeconds"
	
	if (remainingSeconds is equal to 99999) or (remainingSeconds is equal to missing value) then --timer is not running and should be started
		
		--ask for the duration via a dialog popup
		set dialogAnswer to display dialog "Please set timer using HH:MM:SS (max. 24 hours):" default answer "00:00:05" --edit this to change the default time
		set answer to text returned of dialogAnswer
		set answerHours to text 1 thru 2 of answer as text
		set answerMinutes to text 4 thru 5 of answer as text
		set answerSeconds to text 7 thru 8 of answer as text
		
		set totalSeconds to (answerHours * 3600) + (answerMinutes * 60) + answerSeconds
		
		set_number_variable "remainingSeconds" to 99998
		
		repeat totalSeconds times --count
			if (get_number_variable "remainingSeconds") ≠ 99999 then -- if the variable is 99999, that means the timer was pressed again and should be stopped
				set totalSeconds to (totalSeconds - 1)
				set_number_variable "remainingSeconds" to totalSeconds
				refresh_widget "2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10"
				delay 1
			end if
		end repeat
		
		if (get_number_variable "remainingSeconds") ≠ 99999 then
			repeat 10 times --blink to signal that the time is up
				update_touch_bar_widget "2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10" background_color "0,0,0,0"
				delay 0.5
				update_touch_bar_widget "2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10" background_color "255,38,0,255"
				delay 0.5
			end repeat
		end if
		
	else --timer is running and should be stopped
		set_number_variable "remainingSeconds" to 99999
		refresh_widget "2CA20DFA-8DAC-4E9A-A095-8BCC75ABAD10"
	end if
	
end tell

Nice! I was about to do something like this for a Pomodoro, I'll take a look into this this might solve some of my problems! :smiley: great work :+1:t3:

For whoever wants to use this, don't forget to adjust the Touchbar Widget UUID in the executable Script. :slightly_smiling_face:
@fidgetspinner by chance, do you know a solution to set the width of the widget to a constant size?

1 Like

thanks! constant widget sizes are not possible as far as i know. I mostly use black backgrounds though, which kind of gets rid of that problem and in my opinion it looks nicer anyway. Maybe you can try that. Good luck with your work, let me know if you make any interesting enhancements :slight_smile:

1 Like

How to download this timer widget?

Whoa, this post was a little crazy! I've cleaned it up for you :smile:

I've also been looking to make a timer too, this seems pretty good.
Does it use any external apps or does it run entirley by itself?

One last thing, this may be a little greed but could I feature this in my AquaTouch Preset? Credits to you in the code of course!

2 Likes

Works all by itself, it uses general BTT variables afaik! :slightly_smiling_face: And just refreshes the widget.
I had some troubles though running it inside an CAG, but I'm working on it. Also trying to improve the time input method, but not sure yet how to manage this!

1 Like

Sounds great! I’m so keen on helping to improve but all the woorkk i wish i didn’t have :frowning:

1 Like

Big fat Exam on Monday :raising_hand_man:t2:

1 Like

year thanks im not really sure how to share widgets. Does it work now? It works all by itself. Feel free to use it in aquatouch!

What's (a) CAG? The input method could really be improved but I didn't have a better idea either

I thought you could just copy the json code (the first piece of code in my post) and paste it in BTT by right clicking and selecting paste from json. If it doesn't work, maybe @yuuiko can help?

Thanks for the permission! Can't get to get it out for people to use!

Unfortunatley BTT is having trouble pasting the code, it keeps crashing. I'm working around it for now and reported the bug to @Andreas_Hegenberg.

Answering;

A CAG is short for 'Conditional Activation Group' that us preset makers use, a feature in BTT that allows you to show a group of triggers based on a set of rules.

@Caliguvara i think the widget needs to be always frontmost so it can update itself constantly... Not sure if it'll work if you exit a group. I plan to add it into the schedule mode but there's a problem if I close that group i need to keep it running.

I suggest opening a group with preset options and a 'custom' button... Something like this but more refined:

  • Tap a time to set it, (it will highlight)
  • Tap start, the group exits and the timer starts.
1 Like

I edited the post and added a download link and info on how to recreate the widget in case importing from downloading and pasting from JSON does not work.

2 Likes

Thanks for the explanation. :wink:

But hey man, a long break should be only 15min long :smiling_imp:

1 Like