Custom HTML Prompt: Save & Restore Position?

Anyone know how to save the position of a Custom HTML Prompt, and restore it the next time the prompt is opened?

I think I know most of the things I need to know to get this to work, but it just doesn’t want to come together. Between the Javascript, HTML, and callbacks to KM, I’m just not getting it.

So if someone could supply an actual example, I’d appreciate it.

Thanks.

I found an answer.

In the submit button’s onclick event, I call something like this:

onclick="submitWindow('OK')"

Which calls this function:

function submitWindow(res) {
  window.KeyboardMaestro.SetVariable('SaveWindowPosition', window.screenX + ',' + window.screenY);
  window.KeyboardMaestro.Submit(res);
}

I also have this function defined:

  function KMWindow()
  {
    var lastPosition = window.KeyboardMaestro.GetVariable('SaveWindowPosition');
    if (lastPosition == '')
      lastPosition = "500,200";
    return lastPosition + ",1100,470"
  }

This positions the window either in the last location, or a default location.

(FWIW, I don’t actually use the variable name “SaveWindowPosition”, but I didn’t want to confuse things by using my real variable name, which is “FcSccPo WindowPosition”. :slight_smile:)

2 Likes