I admit to not being an expert, but what happens if cbArray contains “</div>”? Do they actually behave the same in that case? I don’t think so - the structure of the document remains the same.
The main point remains the same though, I can’t safely parse for any text tokens - at most I could parse for variables, or I’d have to do something to make the text tokens stand out more since % characters are quite common in HTML.
It seems like to me in all cases it is incumbent on the user to provide valid HTML code. If he/she does not, then all bets are off.
I don't see insertion of HTML by JavaScript as any safer than by direct KM variable.
I don't think we were asking for anything other than just KM variables. If the user needs to use text tokens, he/she can do so in creating the KM var in the macro prior to the HTML prompt.
Use whatever syntax you like that would work. How about the shell script notation? That would make it easy to remember.
<script>document.write(window.KeyboardMaestro.GetVariable('Initial'))</script>
or
<script>document.write(window.KeyboardMaestro.Calculate('NOW()'))</script>
or
<script>document.write(window.KeyboardMaestro.ProcessTokens('%Variable%Initial%'))</script>
Correct. Although for just reading the value, you probably want to use the GetVariable function instead of the ProcessTokens as it is simpler, but either works.
I fixed this my making a minor change to Rob's JavaScript:
// --- ALTERNATE JAVASCRIPT BY ROB TREW ---
// Modified by: JMichaelTX Ver 1.1 2016-04-04 16:06 CT
// • Add unique KM Var names for each checkbox
// • This will allow the form to remember previous choices
function run() {
var kme = Application('Keyboard Maestro Engine');
var iCB = 0;
return kme.variables['hashtags'].value()
.split(',')
.map(function (x) {
var cbVal = x.trim();
//--- ADD CODE TO CREATE UNIQUE NAME FOR EACH CHECKBOX ---
// (the HTML name tag is the KM Variable Name)
iCB = iCB + 1
var nameCB = "HT_CB_" + iCB
var htmlStr = '<label><input type="checkbox" name="' + nameCB + '" value="' +
cbVal + '" data-ignore></input>' + cbVal +
'</label>\n<br />';
return htmlStr;
})
.join('\n');
}
I followed your advise and it works great for me as it supports my preferred way of entering data by keeping my fingers on the keyboard. Typing two or three letters is faster for me than selecting options with a mouse.
However, there is a problem of different apps behaving differently when you enter several hashtags as they use different delimiters (space, comma, tab...). Therefore I wonder what would the most efficient way to enter this delimiters. Please advise.
If you are saying that different apps need to use different delimiters, then you can simply add a Switch/Case Action based on app name:
Here is an example Action (actually stored in my KMFAM).
Note that I have renamed the Switch/Case Action.
Replace the app names with the ones that you want to use.