How to start a second timer and decrement it efficiently in a while loop?

I have a macro I want to make that makes me take scheduled breaks for 3 minutes and forces me out of using my laptop or only let me use one app. Here is the macro I have made and have so far:

Timing review break.kmmacros (48.5 KB)

There is only one thing I don't know how I can do.

So this macro will be run scheduled every 2 hours. It will open an app and let me review things I've done and start a timer. I was thinking I could start a timer by creating a variable BreakTimeSeconds and setting it to number of seconds.

And then go into a while loop that will force me to not switch from Timing app until the timer is done. How can I decrement running down this timer efficiently? I am a bit confused by this.

Thank you for any help.

One not-too-terribly-difficult way to do this is to make a timer subroutine macro:

BreakDownSeconds Subroutine.kmmacros (2.3 KB)

Then have your current macro execute it asynchronously after setting the timer variable:

I just tried this and it doesn’t work. It send hundreds of notifications and acts really weirdly if the whole thing is worked with the while loop after in the main macro.

Hmm. If what you want is to be forced to use only this Timing app for the three minutes that the timer is running, you don't need the "activate last application" action that runs if Timing is at the front. Try disabling these actions at the very end of the macro:

and then it should automatically bring Timing back to the front with the notification only if you try to switch away from it.

1 Like

Thank you a lot @gglick

This macro is working superbly. Here is the final macro I am using in case anyone want to steal it.

Timing review break.kmmacros (49.4 KB)

Only thing I am wondering though is whether calling a notification and this while loop together with a sub macro that computationally expensive? I think this is the best you can do but I am open to suggestions on how to improve it.

Glad you got it working! I have to admit, this is a very good idea for a macro :slightly_smiling_face:

Regarding the computation expense, thanks to iStat Menus, I can tell you that running the two macros on my system makes KM’s process take up an average of 20%+ on one of my CPU cores, which doesn’t seem like nothing. However, a barebones macro that only pauses for 10 seconds makes KM’s process take up around 9% CPU, so considering the difference in complexity I’d say that a 20% average seems like a reasonable trade-off.

Also I am curious, will these macros ran whilst my computer is asleep? I only want them to activate when I am actually using my laptop.

That one I can’t answer for sure, but I would guess the answer is “no”.