In a multi-screen environment, I need to know the screen index (or left,top coordinate) of the screen where the 'KM-custom HTML-prompt' is currently displayed (even if the user has moved it to another screen after launch). The KM function SCREENINDEX('Front') doesn't help, because it returns the screen index of the currently active application, which does not equal the index of the screen with the 'KM-custom HTML-prompt', even if it (also) currently has focus (both red, yellow, green buttons are not grayed out).
Try something like this -- only one display to hand, so not rigorously tested! If you might have more than one HTML Prompt and/or KM dialog open you'll need to get more particular in the AppleScript, eg by getting the bounds of the window with a certain title.
Edit to add:
You'll have to decide how you determine which screen the dialog is on! KM is smart and returns the index of the screen containing the majority of the window in question. I'm stupid and have simply returned the screen containing the top-left corner of the window.
Thanks @Nige_S for your interest and your example macro. I am not sure if it is a misunderstanding, because I probably expressed myself unclearly. I didn't mean the 'Prompt for User Input' action, but the KM action 'Custom HTML Prompt', which is not an engine window.
I know that it is easy to collect the screen bounds of all screens and once you know a coordinate of the Custom HTML Prompt, you can very easily calculate the index of the screen that contains this Custom HTML Prompt.
But the difficulty is to get this one coordinate, unless you use 'onmouseenter', 'onmousemove', or 'onclick' and hope that the user will perform such an action on the custom HTML prompt at that very moment.
The whole thing is also made difficult (in my opinion) by the fact that both the Custom HTML Prompt and any other app can have focus at the same time, so the KM function SCREEN(Front) doesn't help either.
Currently I help myself with an 'onmouseenter' in the -element of the Custom HTML Prompt and then call event.screenX and event.screenY , which fires a nonempty coodinate some milliseconds after the custom HTML prompt is fully loaded (if the user has his mouse on the Custom HTML prompt).
Close all KM "Display Text" windows, "Custom HTML Prompts", etc. Run the macro and you'll first get an empty dialog because there is no Engine window to get the id of, then it'll put up a "Custom HTML Prompt", then a dialog showing the id of that prompt.
Change id in both AppleScripts to name and you'll see how you could use <title> to target one prompt among many.
I may not have tested the original on a multi-screen setup, but I did test it with a "Custom HTML Prompt" both fully on-screen ("Window found on screen 1") and with the top corner off-screen to the left ("Window not found"). If it didn't work for you then post how you tested it along with the macro used to put up the prompt.