Using Prompt With List to modify variables on the fly

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:

<a href="%Variable%zztemp_TheURL%"></a>__HTML

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.



The entire macro is attached now, instead of just a comment action. Whoops! (Thanks, _jims!)


@griffman, very clever and super useful; thanks for the clear explanation and for sharing your macro.

I do have an enhancement to consider. If, in the first list, you included a markdown link rather than just the hyperlink you could:

  • add a fourth option (markdown) in the second Prompt With List
  • use the markdown link text (either by default) or if the second list was dismissed with a modifier pressed, as the default value in the Link text (Cancel for none) dialog.

I'm selfishly making this suggestion because I use markdown links frequently. Rob, if you aren't interested in making that enhancement, let me know and I'll take a crack at it.

On a related note, I discovered the Prompt With List double underscore feature when I was developing Augment or Filter Text.

That macro also includes two Prompt With Lists each including a category of text transformation. It uses the hidden portion of the PWL first entry (to the left of the two underscores) as a method to quickly bypass the first category and move onto the second Prompt With List.

As I never write in Markdown, it's something you'll have to add yourself :).



Oh, darn; it was worth a try. :wink:

1 Like