I have a long timeout Macro and trying to get a very prominent indication on display if Macro is running

I have seen examples where adding a custom html prompt at the beginning of macro and closing at the end of macro, but if the macro timeouts in between, the window won't be closed.

I am looking for a "Macro running" trigger to activate the window and "Macro not running" trigger to deactivate it.
(Basically just like palettes work so flawlessly. If application comes in front, palette shows up, once application loses focus palette disappears.

Thanks in anticipation

I am not one of the elite superusers on this forum so my answer may be imperfect.

I think the problem with your idea is that there is a difference between the copy of the macro that you see in the editor and the copies that are running. You see, the editor shows only a "template" for the running macro. When the macro runs, it can run many copies at the same time! And that means you can have multiple HTML prompts open. Which HTML prompt window corresponds to the copy of the macro that you are editing? There is no answer to that since there is no correlation between the macro you see in the editor and the multiple running copies.

I think another way you could word your requirement is this: "When an instance of a macro closes, I want the following Actions to be run." This would probably be attached to the macro itself in the editor. I think that would achieve your goal. Some languages have this capability. This feature would allow you to close the HTML window.

I'm afraid I can't speak towards your palettes comparison because I have never used them.

I assume by "macro timeouts" you mean that some Action in the Macro has timed out, and thus the Macro was aborted.

If this be the case, the way I handle this is to uncheck the Action Option (in the Action Gear menu) "Timeout aborts macro", and then do an IF/THEN test in the next Action using the %ActionResult% token to determine if the Action did time out.

If so, I then do whatever macro cleanup I need (like closing an HTML Prompt window), and then issue a "Cancel Macro" Action.

If you need further help with this, feel free to post your follow-up questions below.

There is no good way to detect when a macro finishes abnormally (finishing normally is easy since you can just append an action).

The only way you could do it was to have a periodic poll determine if there are currently any running macros. You can do this via the executing AppleScript property of the Keyboard Maestro Engine:

tell app "Keyboard Maestro Engine" to executing

You could have a Custom HTML Prompt window periodically ask the engine that. Although this may be a challenge since you have to do it without actually executing a macro (otherwise it would be executing in any event). I actually can't think of any simple way of doing this. You'd probably have to have some sort of script running asynchronously, asking the engine if anything is executing, and then telling the Custom HTML Prompt window.

An alternative would be to have your long running macro “poke” the Custom HTML Prompt periodically while it continues to run, and if the macro fails to check in for a long enough time, then the Custom HTML Prompt can assume that the macro has terminated.

That's very interesting and inspiring. I might be able to use that, from outside KM entirely, to safely shut down the Engine about once an hour and restart it, so that it comes down to the baseline value of 134 MB each hour. I think I know how to get the PID of the Engine, and I'm working on getting the top command in macOS to report how much memory the Engine is using.

1 Like

You could just do something like this:

tell application "Keyboard Maestro Engine"
	set t to 0 + (calculate "IDLE()")
	if t > 20 and not (executing) then
		quit
		delay 1
		launch
	end if
end tell
1 Like

Super. I can probably figure out how to schedule that as a task. Thanks. However if I can reduce my plist file from 72 MB to maybe 10 MB that may mitigate this requirement.