In my work, I paste the same URLs over and over quite a bit—links to our product pages, or to FAQs, etc. But I paste them in many spots—email, HTML files, and our ticket system. For each place, I need the URL in a different form—either plain, bracketed, or as a full HTML href with link text.
I used to use a couple palettes (one with URLs, one with formatting options) to handle this, but a long list in a palette is pretty ugly, and sometimes my second palette would vanish before I could make a selection. So over the weekend, I was looking at the Prompt With List action, and discovered something magical: You can manipulate variables directly in the Prompt With List box.
This is possible because you can have Prompt With List store a different value than what's displayed, like this:
green__The color green
This would store green
when the user selects The color green
. I wondered if you could use variables on the left side of those statements, and you can—but they have to be global variables, not temporary or instance variables.
Using this newfound knowledge, I was able to replace my two-level palette solution with two Prompt With List boxes (with some extra features). It flows like this:
That's the most-complex use case, a URL that I need in <a href
format, with a text link. In its usual form, it's just steps 1 and 2, and all the URL processing happens within the second prompt box. How?
Prompt 1 stores its results in a global variable, zztemp_TheURL
. Then, in the second prompt box, the input options look like this:
<%Variable%zztemp_TheURL%>__Bracket
<a href="%Variable%zztemp_TheURL%"></a>__HTML
%Variable%zztemp_TheURL%__Plain
You can see how the brackets and HTML text is added to the variable from the first list, while the plain option leaves it alone. If the user chose HTML, the macro then asks about the link text, and inserts it using a search/replace.
But basically, my complicated palettes with case statement were replaced with those two input boxes and inline handling of the URL. And because of that, I was able to add a couple other features—if I hold the Option key in the first box when I make a selection, the URL opens in my browser; if I hold the Control key, then the URL is copied but not pasted.
All-in-one URL handler.kmmacros (15 KB)
I've attached a generic version here, not so much for the URL handling usage (though it may be useful if your work involves providing the same URLs many times a day), but more to demonstrate what you can do by processing a variable directly within the input box.
Maybe this is obvious to everyone, but it wasn't to me.
-rob.