KM Editor and KM Engine window detection and change triggers

I would like to be able to detect the location of each of the windows that KM (either the Editor or the Engine) provides. See list below. I would also like the "Focussed Window Frame Changed" trigger to trigger when these windows change. Only one of them currently triggers that trigger. I tried to get the location of the Progress Bar window using AppleScript but failed. Apparently AppleScript requires that any window be "focusable." So I was able to use AppleScript to get the location of the Value Inspector window (see code below.) But this is not much help because that window's location is also fetchable using tokens such as "%FrontWindowFrame%". The Find Image action is able to find some of these windows, but not all of them.

Window Name Does it trigger Focus Window Frame Changed?
KM Debugger Window Does not trigger
Value Inspector Window Does trigger
Progress Bar Window Does not trigger
Mouse Display Window Does not trigger
Macro Inspector Window Does not trigger
Icon Chooser Window Does not trigger
Debugger Window Does not trigger

Is anyone aware of ways to get around this limitation? I did search these forums. These may be consequences of the design of KM, and may not get changed. But I can still ask.

You're out of luck.

The trigger only triggers when the focussed window changes. Which is generally the current text input window of the current front application.

Keyboard Maestro Engine will never be the front application, so it’s windows will never influence that trigger (so that rules out the Debugger, and Progress Bar and any other Keyboard Maestro Engine windows).

Also, any window that never has focus will not be the focussed window, so that rules out the Mouse Display, Macro Inspector, and Icon Chooser.

Thanks, buddy. I accept that. What about my opening question, "I would like to be able to detect/determine the location of" these windows? Especially the Progress Bar window.

You can probably do that using AppleScript.

It's just another Engine window. The trick will always be to decide which Engine window, if you've more than one up, and the easiest way is to leverage the window's "Title":

tell application "Keyboard Maestro Engine"
	return bounds of item 1 of (get every window whose name contains "Progress")
end tell

I had already tried that code, but written as follows:

set progressWindow to first window whose title contains "HELLO"

And that didn't work. I'm not sure why. (My Progress Bar window contained the word "HELLO" as a test.)

But your code works. However two of the windows above don't seem to have "titles." Do you have any idea how to get their positions?

Windows have name in AS, not title. Perhaps that's why?, Otherwise, difficult to say without seeing the rest of the code.

Getting the positions is easy -- relating a single bounds to one of two windows with the same name (your Progress Bar window will still be named "Keyboard Maestro Progress" if you set the title to nothing in the action) is more difficult. Ways round it will depend on what you are trying to do -- going by z order may be enough (not directly, all background app windows have an index of -1, but it can be derived from AS list of all windows) or you may have to log window ids when you spawn them so you can refer to them later.

@Airy @Nige_S in my limited testing, the progress bar’s name does not change, irregardless of what it’s text contains. Therefore, it’s quite easy to get it’s bounds, even if other Engine windows exist. See the following AppleScript that works on my end.

AppleScript (click to expand/collapse)
tell application "Keyboard Maestro Engine" to tell (first window whose name is "Keyboard Maestro Progress") to return bounds

Yeah, Progress is relatively easy, because it's an Engine window. Some other window types need slightly more work.

  • KM Debugger is fine
  • Value Inspector -- it seems you have to have the KM Editor frontmost, then you can access the window via System Events
  • Progress Bar is fine
  • Mouse Display -- same method as Value Inspector
  • Macro Inspector -- as Value Inspector
  • Icon Chooser -- as Value Inspector

General pattern to get the properties of the Value Inspector:

tell application "Keyboard Maestro"
	activate
	tell application "System Events"
		tell application process "Keyboard Maestro"
			properties of item 1 of (get every window whose title is "Value Inspector")
		end tell
	end tell
end tell
1 Like

That's probably why my test searching for "HELLO" failed. In any case, I've got lots of food for thought in this thread. Thanks.

1 Like