Display Text in Centered Window [Macro: KM10]

Hi Chris,
can you get the updated macro again.
I changed the following:

  • get km variable using KM.GetVariable instead of from document.kmvar (even though it works from my side, but I suspect it could be this)
  • add try catch block in KMInit function in order to log error message to be shown in Web inspector console.

thank

I had to turn on webkit debugging:

defaults write com.stairways.keyboardmaestro.engine WebKitDeveloperExtras -bool YES

Chris,

I see. I think you're running an older version of MacOS with wkwebview that does not support the recent Javascript standard? If so, it does not recognise the Optional chaining operator:

[Optional chaining (?.) - JavaScript | MDN]

Can you search and replace ?. with . instead in the code at your side to see if that works for you ?

For example:

KM?.GetVariable becomes KM.GetVariable

My webkit version is
image

thank

Yes. Mojave as I mentioned:

'5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'

Your suggested patch fixed the problem – it's working now.

Thank you.

Chris,
Np.
I have updated the macro to use document.kmvar. One advantage of using document.kmvar in async custom prompt is that I don't have to add a pause action after the prompt action. Without the delay, there is possibility that the macro is completed before the prompt get the chance to read the local variable (happen especially if prompt is the last action of macro). Another possibility is use global variable which I try to avoid if can let do with local variable.

1 Like

@macdevign_mac — I'm trying it out. Thus far, I like it.

Is there a possibility to add the ability to close/dismiss the window by typing the Esc key?

Jim,
you try the 2nd version that I upload. You can press any key (including ESC key) to close the window as long as it is in focus. Once window lost focus, clicking on the window will close it.

1 Like

I just downloaded the 2nd one, and when I run it, I just get:

This is default message

I am not sure what I am missing, as I set it up like version 1.

Jim,
What is the value of Local_inputJson variable before calling the prompt ?

What is the error show in custom prompt inspector console as I could not replicate the problem at my side ?

I suspect Local_inputJson is not passed correctly hence it display the text.

The issue looks like it was useFirstInput set to false.

In version 1, that was set to true.

I didn't catch that it was set to false in version 2.

It seems to be working now. Thanks!

Back to testing/trying it out.

How might one set KM variables to provide the textSize in pt, width in px and delayInSec?

@macdevign_mac — Thank you for this macro! You have no idea how happy I am that you created and shared this at this time! Kudos!

I am going to be moving about a dozen macros to use it to display various messages throughout my day.

A couple of desires:

  1. Would it be easy to move all of the settings into the Custom Prompt with HTML part? This would make it easier to integrate into my existing macros.
  2. Since my messages are designed to interrupt me (Stand up for 1 minute!, or Colemak-DHm Typing Practice Time! for example), I may be typing when it appears, and my typing may accidentally dismiss it. It is easy to change the Press any key to close the window to only the Esc key will close the window?
  3. In my own attempts at designing one of these display messages, I have found that a message that blocks the entire screen is very helpful, as it fully catches and focuses my attention (example screenshot below).Can your code display the background over all (or most of) of the screen? My attempts at making your macro full sized have failed this far (second screenshot).

1 Like

Great macro @macdevign_mac - thanks!

It would be even better if it didn't always display on the main screen. To explain - I have a 2-screen setup and you macro always displays on the main screen. I want it to display on whichever screen contains the frontmost app window when it runs.

In your code I changed

data-kmwindow="SCREEN(Main,Left,35%),SCREEN(Main,Top,17%)"

to

data-kmwindow="SCREEN(Front,Left,35%),SCREEN(Front,Top,17%)"

but it didn't have the desired effect.

Any thoughts on how to achieve this?

BUMP: any thoughts at all in this question @macdevign_mac ?

FYI—I was able to figure out the Esc key part.

I changed:

document.addEventListener("keydown", (event) => {
    closeWindow();
});

To:

document.addEventListener("keydown", (event) => {
    if (event.keyCode == 27)
    closeWindow();
});

And I have been able to condense the macro.

But I still need help making the display fullscreen.

Jim,
use this custom version to fill whole screen and close on Escape key. Even though it center the text, you may need to twitch the CSS accordingly.
displaywindow.html.zip (3.4 KB)

tiffle,
For this, I have no idea as the front seem to be the correct parameter according to the wiki at
https://wiki.keyboardmaestro.com/function/SCREEN
Most likely you need to try rest of the index value for the SCREEN index parameter to figure what's work. Perhaps you can ask Peter on this ?

troy,
the variable "Local_inputJson" is used to specify those values as shown in example. The custom prompt retrieve those values from Local_inputJson variable using KM's GetVariable function..

Troy,
you can use the subroutine version that I upload as it is easier to use.

Great! Thank you!

There is a bit on the left edge where the background shows. Any ideas on how to adjust the window to cover that?

Screen Shot 2022-01-26 at 8.55.47 PM

Jim,
you need to adjust value of Screen Top, Left, Width and height in the body tag.

<body data-kmwindowid="displayTextWindowApp" data-kmwindow="SCREEN(Main,Left,35%),SCREEN(Main,Top,17%)"

You need to play around with this because what work at my side could be different from yours.

@macdevign_mac — Thanks!

This seems to work on my screen:

<body data-kmwindowid="displayTextWindowApp" data-kmwindow="SCREEN(Main,Left,104%),SCREEN(Main,Top,100%)"

Answering my own question here:

To get the Custom Floating HTML Prompt to appear centred in whichever display currently contains the frontmost app, you just insert the following action prior to the Custom Floating HTML Prompt action:

KM 0 2022-01-31_22-55-53

1 Like