Combining several things I've learned over the past few months, this is a stripped-down example of how to create a Custom HTML Prompt that does the following:
Saves/Restores its position, so it will show in the same position on the screen as the last time you used it.
NOTE: Exiting the prompt by pressing the Escape key does NOT save the position.
Specify the Width and Height of the prompt using KM variables.
Dynamically sets the HTML "body" style to values that work with the Width and Height.
There's only one place to change the values, making it easy to keep everything in sync.
Easier for Users to change the width and height, if needed, rather than digging through HTML and css code.
Dan! You must stop this! My hard drive is nearly full from downloading all of your Macros. I've had to hire an assistant just to keep up with this. LOL
Another great macro from Dan the Macro Man!
I'm adding this to the "Best Macros List".
LOL. Get used to it. This is what I do. I used to do it for a living. I’ve always been the “tools guy”.
Whenever I find myself saying “there’s got to be an easier way - hasn’t anyone done this before me?”, I figure that once I figure out how to do it, I may as well document it for others.
It’s actually kind of an obsession for me - almost OCD-like. You could probably tell.
@iNik and @DanThomas, this is so great and saved me tons of time trying to configure this myself
a question arises though. @iNik, im using your implementation adding the script part to the html. Yet how does one address several html prompts with different sizes?
I tried changing the TestDefaultWindowSize to a unique variable per prompt ie to ws_mailmate, and adjusted that in the code with no success.
Ok..answering myself, i did get it to work, but it seems to me in a very hacky way..i changed both variables on the html script to unique variables, and this seem to work now:
<script>
function KMInit() {
window.addEventListener("resize", savePosition, true);
window.addEventListener("unload", savePosition, true); //this doesn't seem to work
}
function KMWindow() {
winBounds = window.KeyboardMaestro.GetVariable("ws_hyper2");
if(!winBounds) {
winBounds = window.KeyboardMaestro.GetVariable("ws_hyper");
}
return winBounds;
}
function savePosition() {
window.KeyboardMaestro.SetVariable('ws_hyper2', [window.screenX, window.screenY + 16, window.innerWidth,window.innerHeight].join(',') );
}
function submitWindow(event) {
savePosition();
window.KeyboardMaestro.Submit( event );
}
function cancelWindow(event) {
savePosition();
window.KeyboardMaestro.Cancel( event );
}
</script>
Here is an untested idea: Try using either Local or Instance Variable . I would try Local first.
If this works as I expect (untested), then each Macro that uses the HTML Prompt will have a separate copy of the Local variable, and there should be no conflicts.