Mac Menu countdown timer? Bitbar?

@DanThomas and @iNik had some suggestions that got me started in the right direction here:

I’ve been wanting to integrate Bitbar with KM to do a Countdown timer, but I’m not sure what the best way to pull this off is. I think this could be really useful to people who want to Timebox their tasks and automatically advance from one thing to another in specific increments.

I built a simple Timebox solution while I was on an animation project. It forced me to work fast and push through all the frames. Once I went through the rough pass, I went back and cleaned things up. The timer control made things infinitely more do-able to meet a short deadline.

However, I would like to have the time remaining countdown somewhere visible, like the menu-bar.

Any suggestions?

Here is a way to do it using Custom HTML Prompts. Adjust as necessary.

Keyboard Maestro 8.0.5d1 Actions

Keyboard Maestro Actions.kmactions (2.2 KB)

Thank you Peter! It's very helpful to see a better understanding of this method. I may hybridize a Custom HTML prompt into the solution I came to below so that I can get a little more sophisticated in how I manage my time blocks, so this example is very helpful.

If anyone's interested, and wants a timer on their top menubar I figured out you can use Bitbar like so:

  1. Download Bitbar and countdown timer script for it.
  2. Make sure the script is named 1s so that it will refresh every second.
  3. Set the variable in KM
  4. Launch countdown timer script with this shell script that passes the variable in:
    ruby /bitbarLocation/countdown_timer.1s.rb "$KMVAR_bitbar__timeAmount"s

BigImage

In the example javascript, how could one automatically dismiss the custom HTML prompt window when the countdown reaches zero?

Any way to make the background turn a color when the time expires or even better, set the system volume to xx and make a sound?
Or even flash the menu bar until you address it?

  • Just some thoughts, thanx…

Just call window.close() in the JavaScript.

1 Like

You can do any of that, either using JavaScript control, or by triggering a macro like:

window.KeyboardMaestro.Trigger( "Macro Name", "Trigger Value" );
1 Like

where do I put that code exactly? I tried a couple places within the html, …
window.KeyboardMaestro.Trigger( “Countdown Timer Display Test”, “1” );

If I add the statement window.close() anywhere in this script, it not only doesn’t work, it crashes the KM engine. If I create a new function that contains this command, same result.

Obviously I don’t know enough about Javascript to do this correctly, so any further help would be appreciated.

1 Like

here's where to put the code for triggering a macro, in case anyone else isn't really html savvy like me.

SetClock();

function KMInit() {
	var timeinterval = setInterval(function(){
		SetClock();
		if( !SetClock() ){
			clearInterval(timeinterval);
window.KeyboardMaestro.Trigger( "Countdown Timer Display Test", "Trigger Value" );
		}
	  },1000);
}

For the "close window" put

window.close();

where I have put

window.KeyboardMaestro.Trigger( "Countdown Timer Display Test", "Trigger Value" );

or you can have them both.

OK, finally figured it out. The window.close statement has to follow the line clearInterval(timeinterval);

Still not sure why KM engine crashes when the close statement appears elsewhere. From the log:

2018-02-12 18:20:31 Engine Starting 8.0.5
2018-02-12 18:20:32 Starting web server on ports 4490 and 4491
2018-02-12 18:20:39 webView didFailLoadWithError Error Domain=NSURLErrorDomain Code=-999 “(null)” UserInfo={NSErrorFailingURLStringKey=file:///var/folders/0m/fp782n6s6b1394nxg0q4rbsr0000gn/T/Keyboard-Maestro-Custom-Prompt-930B880F-6E10-4140-8AD0-D3A6265EA61D.html, NSErrorFailingURLKey=file:///var/folders/0m/fp782n6s6b1394nxg0q4rbsr0000gn/T/Keyboard-Maestro-Custom-Prompt-930B880F-6E10-4140-8AD0-D3A6265EA61D.html}

I have fixed this crash for the next version. Thanks.

Hey Peter sorry to start this up again but did you build a next version of this? also wondered how you would get an alert dialog every 10 minutes of the countdown. So if the countdown was set for 30 minutes at 10 minute intervals an alert would pop up. Also is it possible using this to pause/continue the timer at all in that window?

I'm having trouble understanding what you are trying to do. I suggest you start a new topic, with a full articulation of what you are trying to do (including, if appropriate, a reference to this thread).

As far as “next version”, the crash reported about has long since been resolved.

Hello everyone,

First of thank you so much for this macro, I use it for my focus sessions (pomodoros) and it's working wonders for my productivity to have the html prompt always visible.

I wanted to ask, how could I add a cycles counter to it ? I would like to count how many pomodoros I did, and display them under the timer like "1 of 10" , and everytime the timer ends it increments this counter's value by one, then resets to 0 on the next day.

The goal is to count how many pomodoros I do in a day, every day.

I would be very grateful if someone could help with this :pray:

Thanks,
Mehdi

Hi everyone,

I spent some time on it this weekend and managed to solve it :slight_smile:
So here it is if anyone's interested, it makes a great pomodoro timer & counter :+1:

Focused Session.kmmacros (7.3 KB)

Cheers,
Mehdi