With KM 8’s “resizable” option for HTML prompts, is it possible to retrieve the size of the window or otherwise save it so that the next time I get prompted, the new size is automatically applied? (ideally, position, too!)
Figured it out:
function KMWindow() {
winBounds = window.KeyboardMaestro.GetVariable("savedTestWindowPosition");
if(!winBounds) {winBounds = "25,25,640,480";}
return winBounds;
}
function savePosition() {
window.KeyboardMaestro.SetVariable('savedTestWindowPosition', [window.screenX, window.screenY, window.outerWidth,window.outerHeight].join(',') );
}
function submitWindow(event) {
savePosition();
window.KeyboardMaestro.Submit( event );
}
Feature request, @peternlewis: Have the window handle a beforeUnload event so that whether the window’s submitted, cancelled, or just closed/escaped, we can call a function. I tried using this script and didn’t have success:
function KMInit() {
window.addEventListener("beforeUnload", savePosition, true);
}
2 Likes
In case it’s useful for others, this event listener DOES work, so at least you can save the window position if you resize it:
window.addEventListener("resize", savePosition, true);
Demo macro that does this thing. Shout out to @DanThomas for pointing me in the right direction.
Custom HTML Prompt that Saves Size and Position.kmmacros (3.9 KB)
1 Like