How to make macro pause based on results of Javascript in HTML

I'm finishing (I really hope!) a macro that will do some backup activity. To interact with the macro, the user must press the Control key within three seconds of the macro's startup. Right now, I'm trying to use this HTML/Javascript to display a countdown timer:

<!DOCTYPE html>
<html lang="en">
		<meta charset="utf-8" />
		<style type="text/css">
		body {
			font-family: -apple-system;
			font-size: 14px;
	<body style="background: #e6ffac"" ">
		<p style="text-align: center">
			<b>The backup will start in <span id="counter">3</span> seconds…</b><br><br>Press the Control key to change settings or cancel the backup…

			setInterval(function () {
			}, 1000);

			function countdown() {
				let i = document.querySelector('#counter');

				i.innerHTML = parseInt(i.innerHTML) - 1;
				if (parseInt(i.innerHTML) <= 0) {
			function KMWindow() {
			// fromleft, fromtop, width, height
			return "500,300,460,130";

			document.addEventListener("keydown", function(event) {
				if (event.ctrlKey) {
					window.KeyboardMaestro.Trigger( "•main | Settings manager", "Trigger Value" );


			document.addEventListener("keydown", function(event) {
				if (event.key === "Escape") {
					event.preventDefault(); // Prevent the default behavior of the "Escape" key


If I let the timer lapse, the window vanishes and all is good. But if I click the Control key, the settings manager appears, as it should…but the macro keeps running, starting the backup. I need it to pause until the settings manager is gone, and I'm not sure how to do that.

I know v11 has an "executing macro" condition which might work, but I'd prefer to keep this macro v10 compatible, if I can.

One workaround I tried was using a "pause until MyCheckVar is false" after the above HTML prompt. I then set it to True when the Settings Manager opened, and then to false as the last action before the settings manager closed.

This worked, except the settings manager is a prompt with list, which a user can cancel with the Escape key. And if they do that, my flag variable doesn't get changed, and the macro just sits there.

Is there an easy way to do what I'm trying to do? (All this in the interest of having a live countdown timer…I have a static solution working with a static progress bar, but it's boring and not ideal.)


Instead of calling the macro directly in the Custom Prompt Action,
you can make use of
window.KeyboardMaestro.Submit('OK')/Cancel to return a value which can be checked through %HTMLResult% and proceed to display Setting Managers Prompt list in subsequent action.
This should work since the backup should proceed only after the prompt list?

action:Custom HTML Prompt [Keyboard Maestro Wiki]

1 Like

The user would then have to click an OK button, right? I'd like to make it as simple as tapping a key. I'm wondering if I can use the %ExecutingMacro% token; going to experiment with that a bit now.


No, the user don't have to click OK, the "OK" is the value return, and it is not a button. The value passed to submit can be any value, which will be assign to %HTMLResult%

OMG, that's brilliant—thanks!

For anyone looking in the future, I replaced the call to launch the macro with this:


And then added a "Case" check after the HTML prompt to see if the %HTMLResult% contained OK or not. The only time it will is when the user presses the Control key.

Thanks again!