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">
<head>
<meta charset="utf-8" />
<title>MacroBackerUpper</title>
<style type="text/css">
body {
font-family: -apple-system;
font-size: 14px;
}
</style>
</head>
<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…
</p>
<script>
setInterval(function () {
countdown();
}, 1000);
function countdown() {
let i = document.querySelector('#counter');
i.innerHTML = parseInt(i.innerHTML) - 1;
if (parseInt(i.innerHTML) <= 0) {
window.close();
}
}
function KMWindow() {
// fromleft, fromtop, width, height
return "500,300,460,130";
}
document.addEventListener("keydown", function(event) {
if (event.ctrlKey) {
window.close();
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
}
});
</script>
</body>
</html>
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.)
-rob.