Check if the Clock app's timer is running

I'm trying to write a km macro which will do the following:

  • If the Timer in the clock app is running – there's a count down in the menu bar – then cancel it
  • If the timer is not running, i.e., no countdown in the menu bar, do nothing

For the first part, I can bring the clock app to the foreground, and then get KM to press the cancel button and quit the clock app. But how can I create the "If" bit to see if the countdown timer is running? This is the part I'm struggling with.

Any ideas on how to achieve the objective would be most welcome. Thanks.

You can easily use and IF statement with a "Find Image" condition that checks if the "Timer" icon is visible in the menu bar. Something like this:

image

It isn't clear to me whether you want your macro to be continually checking for this icon in a loop, or if it's a one time check that you will trigger with a shortcut. Either way should work.

Thanks for your help. I'm new to km, so am still getting up to speed with all the magic it can do.:blush:

It will be a one-time run and I'll combine with a Shortcut, so looks as if this should do the trick. Thanks again.

1 Like

I've taken a screengrab of the timer icon and set up as per your actions but it doesn't seem to recognise it. Never mind. Was worth a try.

Don't give up so easily. How did you screen grab the icon? There are right ways and wrong ways. One of the right ways is use the macOS screen capture utility (CMD SHIFT 4, with the option of setting the system clipboard) and then paste the clipboard into the image will of the Find Image condition.

Think problem is also, if menu bar is translucent and you have a different wallpaper colour from Space to Space, then this conspires for it to fail if on wrong background from where screengrab was taken. Would hope there was something more programmatic to determine if timer was running, to mitigate against this.

1 Like

Try an "If" action with a "Script" condition:

...where the result is 1 when the timer is running, 0 if not (because there will be 0 menu bar items with the description "Timer").

The AppleScript is:

tell application "System Events"
	tell application process "Control Centre"
			return count of (every menu bar item of menu bar 1 whose description is "Timer")
	end tell
end tell

Many thanks for this. Just to be clear, have you tried this with the timer running in the clock app, and it works?

It works for me, but I'm not using Spaces -- YMMV.

Ok, great. Thanks for taking the time. I’ll give it a spin when back at Mac.

Just tested and this seems to work perfectly. Really appreciate your help on this. Cheers.