Update script results in same floating window?

I have this macro that displays the status of an app in a HTML prompt. Every time I run it, it creates a new window.

Would it be possible to make it so that every time it runs, it updates the results in the same window instead of opening a new window every time?

Also, is it possible to make the window semi-transparent black, kind of like the palette?

Unless I'm missing something—which is quite possible—you can't leaving a floating HTML window onscreen if the macro isn't running. So the first trick would be to design your macro so that it's always running while you need to see this status window.

And this might be a good time to jump backwards a bit, and ask what you're trying to accomplish—perhaps there are other ways to get it done, if we knew the main objective.

-rob.

In the styles, set your body's background-color: using rgba (red/green/blue/alpha) rather hex:

background-color:rgba(0,0,0,0.25);

...and make sure the "Custom Floating HTML Prompt" action's option is set to "Transparent":

While in the options, set the action to "Asynchronously" so the prompt remains on screen but the macro runs to completion.

Add a "Try/Catch" action to your macro, after the AppleScript action, and put your Prompt action in the otherwise section. Edit the body tag in the Prompt's HTML to add an id you can reference:

<body data-kmwindowid="myCustomPrompt">

In the "execute section of the "Try/Catch" add an "Execute a JavaScript in Custom Prompt" action. Set "Window ID" to the ID in your HTML and set the script as location.reload():

image

Here's a demo showing the main points:

Update HTML Prompt Demo.kmmacros (2.9 KB)

The window will show your system "uptime" in seconds. Run it, wait a few seconds, run it again and you should see the number change.

When you run the macro it will try and update the Prompt window. If there isn't one the JavaScript action will fail and the "otherwise" block is executed, creating the Prompt for you.

Reloading the whole "page" wouldn't be great if you had a large amount of HTML, but I doubt that's the case here. And it is a simple method which even my limited JS abilities can handle! But there are some excellent web coders on the Forum who I'm sure will be able to improve on this.

1 Like

SuperWhisper is a voice dictation app, and you can run different modes (straight voice dictation, pass instructions for the dictated text through LLMs, etc.).
The script shows what mode SuperWhisper is currently running.

I'm currently running a similar macro in the menu bar, but one of the computers I have (MacBook Air M3) only has a 13-inch display, and the mode shown in the menu bar often gets cut off.

What I want to do is run the macro every 30 seconds or so and show what mode is currently selected in a floating window.

Argh, I always forget about that, because I typically build my HTML in a variable then display it using the Execute Javascript in Custom HTML Prompt action. And you can't do that asynchronously.

Bookmarked :).

-rob.

Can't you spawn the Prompt window async, then target it with your "Execute JavaScript" action? You have to wait a beat for the Prompt to become available but, unless I'm missing the point in my HTML-naivety, this seems to be what you mean:

Async Custom HTML from Variable.kmmacros (2.9 KB)

Image

That works perfectly. Thank you so much!

What an obvious and brilliant idea ... no wonder I didn't think of it :slight_smile: Thanks!.

-rob.

Another quick question:

Is it possible to specify the width and height of the HTML prompt window, and also specify its location on the desktop?

Take a look at the action's Wiki page and you'll find both those answers and more.

1 Like

Thank you :pray: