Hey Neil, the body tag is indeed where you can adjust size and position. I'm sure there's a way to automatically adjust the window location according to it's size, but the only way I would know how to do that is via som KM actions which you could pass via a variable; I do not know how to do that using strictly HTML.
As you're probably aware, first two numbers are location, last two numbers are size. Adjust accordingly until you get the desired result.
If you're interested in passing KM variables to the HTML to set size and location let me know and I can help some more.
Right ok thanks. I guess I was perplexed by the fact that the window is centred on all displays regardless of resolution, so I thought there was some auto-alignment going on. Evidently the position has to be set manually. I'll have a play around now.
Actually, I just found that setting that line of HTML that @cdthomer referenced to the below makes a window twice as big and centred slightly up on the screen. It's the last two numbers that set the size - in this case I typed in 600,300 (the numbers in the original code were 300,150)
EDIT - sorry I realise I didn't compensate for the width increase affecting the horizontal center in the code I first posted. I've updated the code above. I had originally left the width portion as Width)/2-150 but it seems to have to be Width)/2-300
Awesome! One last question if you don't mind. What exactly do I have to delete to get rid of the onscreen timer without breaking the prompt's autoclose?
How do you specify the font as Helvetica? I tried replacing utf-8 with helvetica, but that didn't work.
Incidentally does anyone else find scrolling in a code box in KM a bit maddening? Every couple of scrolls, the macro itself decides to scroll down. Would be great if you could "pop-out" actions with text fields to a long-form view with a resizable window. Just sayin'
(The charset attribute is related to the set of characters that are available, and the codes specifiying the point occupied by each character in a table.
Nothing to do with font styling.)
Do you know if I can activate the prompt and, leave it visible and then dismiss it manually at a later stage in a macro, rather than using an auto-close timer?
var timerSwitch = '';
setInterval(function(){ countdown(); },1000);
and
function countdown() {
let i = document.querySelector('#counter');
if (timerSwitch != 'pause'){
i.innerHTML = parseInt(i.innerHTML) -1;
}
if (parseInt(i.innerHTML)<=0) {
window.close();
}
}
The 2nd is used by the 1st. If you delete the 1st, there will be no error; it's just that the 2nd is defined but never used. However, if you delete the 2nd without removing the 1st, it will report error because the function used in the 1st--that is the 2nd function--has been removed.
In addition, the following are also timer-related functions.
The above two functions are used by the following two buttons which should be removed at the same time (otherwise, there will be another error report):
Thanks for that. I've deleted the first two code blocks you cited. Neither of the second two blocks are in the code I downloaded from the top post in this thread, so I'm wondering if there's an updated script somewhere that I missed...?
Can someone tell me or show me how to detect when this HTML prompt window is closed? I want to disable the palette that was used to trigger this and then re-enable that palette when the window is gone.
For passing window height and width, please refer to the post below:
To be more specific, I use a function to resize the window:
function resizeWindow() {
// get the front screen coordinates: top-lef.X, top-left.Y, bottom-right.X, bottom-right.Y
let screenCoordinatesArr = window.KeyboardMaestro.ProcessTokens( '%Screen%Front%' ).split(",");
let winSize = window.KeyboardMaestro.GetVariable( 'instanceWindowSize' );
let winWidth = "";
let winHeight = "";
if (winSize != "") {
let winSizeArr = winSize.split(",");
winWidth = parseInt(winSizeArr[0]);
winHeight = parseInt(winSizeArr[1]);
} else {
winWidth = 540; // Default window width; change the value as you need.
winHeight = 300; // Default window height; change the initial value as you need.
}
// the winX below will set the HTML window to the upper-right color of the front window.
let winX = parseInt(screenCoordinatesArr[0]) + parseInt(screenCoordinatesArr[2]) - winWidth;
let winY = 19; // 19 is the height of the menu bar.
window.KeyboardMaestro.ResizeWindow(winX + "," + winY + "," + winWidth + "," + winHeight);
}
If the following action is activated, then it will use the number set by you, otherwise, the window size is by default as set in the html code.
This gives you some idea how things are handled by javascript functions.
For font size, you can use a javascript function to change it too. You may refer to posts such as
The difference in Keyboard Maestro is that you need to get the KM variable value. This is demonstrated in the code above, such as:
let winSize = window.KeyboardMaestro.GetVariable( 'instanceWindowSize' );