Working on an HTML prompt window and I’d like to center it horizontally on the screen but position it in a specific place vertically. If I I set the left position at 50%, it puts the left edge at the center of the window, but I’d rather have the window entirely centered.
Here’s some code I use that centers the prompt in the screen:
function KMWindow() {
_lastWindowPosition = window.KeyboardMaestro.GetVariable("minstMacroExistsPromptPosition");
var formWidth = "600";
var formHeight = "400";
if (!_lastWindowPosition) {
_lastWindowPosition =
window.KeyboardMaestro.Calculate("(SCREEN(MAIN, Width) - " + formWidth + ") / 2") + ", " +
window.KeyboardMaestro.Calculate("(SCREEN(MAIN, Height) - " + formHeight + ") / 2");
}
return _lastWindowPosition + ", " + formWidth + ", " + formHeight;
}
You’ll need to change it up a little, but this should get you going. Let me know if you need help.
4 Likes
Perfect! Thanks for the assist!
1 Like