How to Screen Capture KM's Custom HTML Prompt?

Hi, is there a way to capture just the HTML prompt window?

Using Screen Capture: Front Window
captures the whole screen

ok, got it working, used parts of script inspired by @DanThomas so I can use dspWindowPosition :grinning:

1 Like

Hello @hello and all other users!

I am having the same challenge as you had. I want to make a screenshot of a Custom HTML Prompt but I can only do this via an area with fixed parameters.

I'm not sure that I do understand what you are saying ... Does your approach get the upper left corner and size of the displayed (to display?) HTML page first and uses that for the screenshot (screen capture in KM Speak)?

This is my Custom HTML Prompt macro:
Test - display Custom HTML Prompt.kmmacros (10.6 KB)

Hey Hans,

You're wanting to automate this with Keyboard Maestro?

It's easy enough to do with the built-in macOS window-capture tool.

4

Spacebar

Click on the desired window.

If automating...

I think @hello is getting existing values for the window frame from the macro he's using.

You should also be able to access the window frame with AppleScript.

I'm not sure about using the WindowFrame token with a Keyboard Maestro Custom HTML Prompt window.

-Chris

2 Likes

I think he's using global variables to set the window position, and which can then be used to do the screen capture area. There are possible problems with this -- if you move the window then try to screen shot it, the globals probably haven't been updated to reflect the new position (I haven't checked the macro, but I'm guessing they update when you close the HTML Prompt).

HTML Prompts are "owned" by the KM Engine, and it's easy enough to get the window bounds with AppleScript if it's the only one open:

tell application "Keyboard Maestro Engine"
	bounds of window 1
end tell
--> {100, 84, 748, 437}

...although those are "left edge, top edge, right edge, bottom edge", so you'll need to do some maths to get to KM's preferred "left edge, top edge, width, height" format.

If there's more than one window/prompt/display text open you'll need a way of picking out your HTML Prompt -- does it have an unique title or anything?

3 Likes

Hey Guys,

Keep in mind that the Keyboard Maestro engine can have more than one window visible at a time, and the Custom HTML Prompt window might not be window 1.

A quick test for this:

tell application "Keyboard Maestro Engine"
   
   set winList to its windows
   set numberOfOpenWindows to length of winList
   
   if numberOfOpenWindows = 1 then
      set theWindow to item 1 of winList
      set windowBounds to bounds of theWindow
      return windowBounds
   else
      error "The Keyboard Maestro Engine has" & space & numberOfOpenWindows & space & "windows open..."
   end if
   
end tell

Note that I don't have a mechanism in place for displaying the error – that is up to the user.

You can also get the window title.

I believe you can also interrogate the HTML Prompt window with JavaScript.

So you can get pretty sophisticated if needed, or you can keep it simple and just assume that any HTML Prompt is going to be window 1.

-Chris

2 Likes

Exactly this, I never fully implemented the macro as this required much more work. As @ccstone commented, I used “magic numbers “ in the end, that’s why the 11 and 37 values.