Close KM "Display Text" window

Hello!

Does anyone know a way to close KM "Display Text" window with a KM action?

09

Hey Kirill,

You have to use AppleScript and System Events and talk to the window/windows in the Keyboard Maestro Engine.

If your system in non-English the "role description" might be localized into something else.

tell application "System Events"
   tell application process "Keyboard Maestro Engine"
      tell front window
         tell (first button whose role description is "close button")
            perform action "AXPress"
         end tell
      end tell
   end tell
end tell

You can use the same basic technique to move and resize these windows as well.

-Chris

Hey Chris,

That's what i have after running your AS:

What may cause the error?

Hey Kirill,

Not sure – it works fine on my macOS 10.12.6 Sierra system.

Try running this:

tell application "System Events"
   tell application process "Keyboard Maestro Engine"
      tell front window
         properties of every button
      end tell
   end tell
end tell

-Chris

Looks like i got it, AS detects a palette as a front KM window and tries to close it, using you script i found the name of the "OK" button in the "Display text" window. So, i have to locate a correct KM window which may be not frontmost.
Please advise.

Whups – I forgot about palettes... :sunglasses:

Try this:

tell application "System Events"
   tell application process "Keyboard Maestro Engine"
      tell (first window whose name is "Keyboard Maestro - Display Text")
         tell (first button whose role description is "close button")
            perform action "AXPress"
         end tell
      end tell
   end tell
end tell

-Chris

2 Likes

Simulate Keystroke "Return" Action.

Works perfectly, as all your other solutions !

Is there a way to close all of them at once instead of one at a time?

Option clicking the close button will close all of the Display Text in Window windows.

1 Like

great! thank you. today i ran the above applescript on repeat about 2000 times. not joking.

Any way to assign it to a shortcut? I tried this, but the modifier hold bit doesn't work and it only closes one of the windows:

activate application "Keyboard Maestro Engine"
tell application "System Events"
	tell process "Keyboard Maestro Engine"
		option key down
		click button 2 of window "Keyboard Maestro - Display Text"
		option key up
	end tell
end tell

Ideally, I'd like to assign it to the Escape key, so the logic would be as follows:

If a window exists whose title includes "Display Text", then ⌥-click it's close button.
Else, simulate the Escape key.

There is no keyboard shortcut.

You can do this:

image

Some notes:

  1. Selecting the Keyboard Maestro Engine requires finding the Keyboard Maestro.app, control clicking on it and selecting Show Package Contents, and drilling down in to the Contents, MacOS folders.
  2. I would recommend changing the setting to by Bundle ID as well.
  3. The Close Front Window action should be configured to Failure Aborts Macro, but also disable Notify on Failure.
3 Likes

Perfect. Thanks!

Something like this?

Window test 2.kmmacros (4.4 KB)

Summary

1 Like

Nice work! Yeah that's exactly what I was after.

FWIW, @peternlewis' version is snappier, as is often the case with KM vs AS, not that it really matters for something like this.

Yep, AS will usually be slower than most other options :frowning:

But my inexperience with KM means I don't know what other windows the Engine might have open, so I went the cautious route and only closed those with "Display Text" in the title bar (as you asked). Really should have gone tighter and used "ends with" rather than "contains", to be even more sure.

2 Likes