Is there a way to Create a Custom HTML Form without Making it "Active"?

After another 10 minutes reading the plot line, you appear to be right.

Nope. The debugger does not display any variables when I invoke it. It never has, and I use it every day. What am I supposed to do to make it show any variables like you have done?

In any case, even if it did work, it looks like it wouldn't meet my needs, because my macro is running asynchronously, showing the values of (selected global) variables as they change. And the debugger window would show the values of variables only when the macro has stopped. So I don't think I would like this solution anyway. I was also hoping to install "data breakpoints" that would do something helpful, like make a sound when a variable reaches a certain value, or something like that. I can achieve this.

My original question is as-yet unsolved: How do I create an HTML form without making it active. Maybe there is no way. I infer that you don't have a way.

Clicking this button toggles showing variables:

image

In any case, back to your original question about your Custom HTML Prompt. What are you doing to refresh your variables? I can't think of any reason focus would need to change, in order to refresh them.

1 Like

WWW OOO WWW !!!!

I had no idea that was even a button! I read KM docs for fun, and I never knew about that button.

1 Like

My Custom HTML Form is not smart enough (neither am I) to "refresh" the variables. It draws a new Custom Form every second. Whenever a Custom HTML form is created, it grabs the focus, right? I want it to remain in the background even when it's created. Is there some way to do that?

You're probably thinking "why recreate the form? Just create a JXA loop and update the data that way." Well, that might work with global variables, but in future versions I also want to pass local variables to it. And as far as I can tell, you can't do that even with JXA. But maybe I'm wrong. Have you mastered inter-instance communication between Custom HMTL actions and other KM macros?

Hello @Sleepy ,

If you mean somewhat like "data breakpoints" for debugging purposes than let me me tell you that there is a way using a system using third party PlugIns called "Check Point System Utilities" made by @tiffle .
I use it several times when needed and it is a great System.

I am really sure that if I am right here - and you are interested in this System - He will invite you into our Private Group so that you can make use of it.

Greetings from Germany

Tobias

Thanks Tobias (@Nr.5-need_input) for the recommendation.

It's obviously up to @Sleepy to decide what's right but for anyone interested in the Checkpoint System they can read all about it here:

Hello Taj (@tiffle),

you're welcome ...

Thanks for mentioning that... but it wasn't my intention to say him what he has to do....
I just needed to tell him about your great Debugging Tool that he can use If I understand it correctly what he wants to accomplish when it comes to debugging.

And thank you for your Tips Post about your Check Point Utilities - I must have missed its existence somehow.

Greetings from Germany to the beautiful France

Tobias

1 Like

Are you saying you create a new Custom HTML Prompt every second?

Yes. This is why I need a way to stop the changing of the active window. Yes, I know it's inefficient to create a new Custom HTML Prompt window every second. But I don't know how to write in JXE so I have to use tricks to get the same end result.

I will consider that, but for now I get my pleasure out of the act of solving problems on my own.

It's an honour to be considered for that. But not now, because solving problems on my own is the greatest pleasure.

How do you currently propagate your prompt with variables and their values? In other words, how does the Custom HTML Prompt know what variables to display, and how do they end up in HTML elements so you can see them?

You've made my day by asking me a question.

In my prototype macro, the user has to register which global variables to monitor, like this: (de-registering is also possible in this macro, and I could also make deregistering automatic when a variable is set to the empty string, or deleted.)

When the user does this, the names of the variables are stored as keys in a dictionary, making it possible for the asynchronous Custom macro to "remember" which variables to draw. In fact, the values of those variables are stored in the value portion of the same dictionary, which means the Custom macro has the ability (not yet implemented in my macro) to determine if the "current value differs from the last value". If there are no differences, the Custom macro doesn't even have to refresh its window! That's efficiency.

I generate the HTML code to display the variables in a table in the Custom form. One of my actions, therefore, looks like this: (it's assembling rows of the table in a loop)

The end result is pretty "plain" at the moment, but surprisingly, it actually works. I think I can work out some of the kinks. But the biggest kink is that I can't figure out how to generate a Custom HTML form without the form becoming the active window on the screen. Maybe there is no way, which means my utility will end up with a lot of "screen flickering".

That's how global variables are managed. now let's talk about the possibility of local variables. Since local variables are outside the scope of an asynchronous Custom HTML macro, my macro cannot access them directly. I've considered a workaround of allowing the calling macro to pass the value of the local variable along with its name. That would probably be implemented by a subroutine that passes both the name and value of a local variable in such a way that the local variable's name and value can be store in a dictionary. As you know, all dictionaries are global variables, so that could be a workaround. But the problem here is that the calling macro has to call the subroutine frequently, which kind of defeats the purpose.

This whole utility is just an experiment. Perhaps it will turn out to be useless for most people. But for today, it's exercising my brain.

All you need to access local variables from another macro is the instance of the calling macro. Have a look in the wiki here: token:ExecutingInstance [Keyboard Maestro Wiki]

Access Local and Global Variables

You could have each macro call your subroutine, passing %AccessedVariables%, on a periodic basis. Except that doesn't give you the Local values. So each macro would need to iterate through %AccessedVariables%, and build a list of variable names and values, which you would pass to your subroutine.

Or...

Each maro could fill a global variable with its current local and instance variables and values, and you could update it any time you want to - it doesn't matter. Because every second or whatever, another macro could access this global variable and use it to update the prompt. But if you do it this way, you'll need to use Semaphores to keep from reading the global variable while you're updating it. This isn't hard at all, by the way. Really easy, in fact.

Updating the Prompt

Now, as far as recreating the prompt each time, here's the logic to not have to recreate the prompt each time: You can use the action "Execute JavaScript in Custom HTML Prompt" to call a function in your prompt, passing the variables and their values.

This will require some effort on your part, including learning some JavaScript. Since you're interested in Custom HTML Prompts, you're going to need to learn some javascript anyway. You can't really accomplish a lot in HTML pages, without some javascript.

So if you're interested in doing something like this, let me know. I can walk you through it, and I can even write some of the javascript so you get the idea. Just be aware that it will take some time to baby-step through the process.

That's what I meant when I said, "That would probably be implemented by a subroutine that passes both the name and value of a local variable in such a way that the local variable's name and value can be store in a dictionary." Except that I said I would use a dictionary, while you were suggesting a variable.

Interesting. I have never used that before. Now I grasp what it's for.

I agree. I have used a little bit of Javascript in Custom HTML forms already, but I quickly forget everything I've learned.

That's a very nice offer. I may take you up on it, but give me more time to consider the direction you've set my sail in.

That would be amazing. I'm very familiar with accessing local and global variables from AppleScript, but despite spending the last 15 minutes trying to figure out how the instance ID of the calling macro would help me find a local variable's value. I couldn't find a single page on the wiki that demonstrates how to use the macro's instance ID to get a variable. But I'll keep looking.

2 Likes

Maybe this will help you:

You’ll need to read the whole thread to get the info you need.

2 Likes

I believe that will help me out a lot. I had never seen that thread before. It will take me days to figure it out, but thanks.

With the tips above, I probably won't have to worry about fixing my original problem in this thread. But putting all the pieces together will take a while.

Good luck!

That is so awesome! Somewhere in the back of my mind, I think I may have learned about this, but I never needed it. But now, I can see how I might use it in my Variable Inspector Prompt. I'll give it some thought.

Thanks!

1 Like

and what is even more awesome is that you might use it in something!

1 Like