2 - The documentation says "Be aware that you cannot use a Keyboard Maestro Variable which itself contains an “_” , because Keyboard Maestro will replace the “_” in the HTML name attribute with a space before it tries to sync with the Keyboard Maestro Variable."
So how can we workaround this? For example when I use the User Prompt I always use Local__varName, because that allows me to add a custom name without seeing the Local portion. So if my variable is Local__varName I won't be able to use it at all or is there a workaround? The only thing I can think of is to convert Local__varName to a new var Localvarname so I can use it with the HTML Prompt. Is this the only way?
3 - Once I have the variable, how will I use it in the form the way I described above? So if I have <label for="title">Title:</label> how will I use the variable to replace the word Text?
I'm not that advanced in JS to do all that, unfortunately... Even the HTML form, even though I'm pretty comfortable with HTML, is a bit of a complex thing for me.
I use the User Prompt quite often and it's simpler/faster/easier (at least at the moment) than customizing the HTML prompt for simple things that take a few seconds. Maybe in the future, if I see that it's easier and I can come up with a template that replaces the User Prompt, maybe I will.
I use that across all macros. It's visually easier to see things.
Sorry, I meant "Title:"
Not the for="title, but the Title: text.
Underscores are great. Unless they are prohibited, of course. Like when using the Custom HTML Prompt. Ya gotta play by the rules.
Are you wanting to replace that text on the fly? That is, the HTML is already displayed and you want to change it? Or are you just looking to build the prompt using data in variables? I guess I'm having trouble seeing the big picture of what you're trying to accomplish.
If it's just building the form using variables, I do this by creating a variable for the HTML. Within that variable, you can reference any KM variables that you want to use, i.e.:
<p>I want the title text to be %Variable%local_myTitle%</p>
With that saved in a variable, say named local_theHTML, I then use Custom Prompt with HTML Text:
That pops up the custom prompt with the variables replaced with whatever their values were when the HTML variable was stored.
If you want to replace bits of an existing HTML prompt on the fly, it's more complicated. Instead of trying to explain it, here's a simple macro that puts an HTML prompt on the screen, then changes its contents.
So we use the variables the same way we use them in any other action using %Variable%Local__varName%
I thought it was different like when you use them in shell where you need to add $KMVAR_ or when using it in AppleScript where you need to add more stuff to make them work.
That makes it easier than I thought.
So then for each variable I need to add this line (adapted to each variable of course):
For example when I posted this I was trying to figure out how to gather some data and using the User Prompt was not ideal. Then the Custom HMTL Prompt was the second option. My goal was to have 14 text fields and next to each field, that text that corresponds to a song, like a title. So if I was gathering the length of 14 songs, next to each field I would have the title of the song so I could see what info I had to put. And those titles are already saved in variables, because of other macros I run before that Prompt.
Meanwhile, after a lot of trial and error, I found out that AppleScript works for what I wanted, because I also needed to make changes to a Numbers document.
But as always, this information you guys shared is going on my notes for future reference, because I'm sure I will use it eventually
You need to be careful about where you're using them. As noted in the HTML Custom Prompt wiki, if you're trying to use them directly in the prompt, they can't have underscores and they're addressed differently.
But I put all the HTML into a normal KM variable, so you can reference any variable in any form, just like you would in any other variable assignment. I then just display that variable in the Custom HTML Prompt action.
No, not right :). That command is only used once to display the prompt that's stored in local_theHTML. You do all the work before then to create the HTML with the referenced variables, then just display it. But if it's an actual input form, then you'll have to use the form handling as shown in the wiki, too—but it should display just fine with whatever values you have stored in variables.
If I'm understanding it, then you just would have built the HTML you needed, referencing all the variables you'e already created, as shown in the first example in my reply. Whatever variables you reference will be replaced with their data when the form is displayed.
I understand what you and @mrpasini are saying about the HTM being in a form. Check my reply before this one. I just added the section and it seems to work.
Is that all I need? At least for this simple form
Yes, if you build the HTML into a variable, you can reference any existing variable using whatever naming convention, as you're just creating yet another KM variable. And then yes, that would be the correct command to displa the variable in a floating HTML prompt.
Thanks for confirming!
It makes it so much easier this way. At least, for this particular scenario. Maybe for other things it would require a different approach?
But for now, I will stick to this.