Token For Selected Text?

In some text expansion apps, you can have a field or token that allows the text to expand around text that's been selected (see what I mean in the screenshot). Is this possible in Keyboard Maestro?

screenshot-08-09-2021-12-34-38

Is this what you mean?:

I think that would only work for text that's actually been copied. I just want to select the text & have the code enclose the text I've selected.

I don't think it's possible. Keyboard Maestro will have to do something to get what's being selected, like a copy action.

What I do is this:

  1. create a macro that contains a brief pause and a copy action:
    Note: I put it in a condition. It only copies when ⌘ is down.
    I'm making the copy action into an independent macro because I will call it in many different other macros.
    image

  2. In other macros, execute this macro, and then do whatever I want with the text.

For instance, I can create a new file in BBEdit and put the text there.
image

What these two macros do is this:
If I want KM to get my text selection, I'll hold the ⌘ key down while firing the macro. If I don't hold down the ⌘ key, then KM will not copy and just process my SystemClipboard directly.

Ok, so here's how I've set up my macro. I get a macro cancelled error though. What am I missing?

screenshot-08-09-2021-15-46-23

screenshot-08-09-2021-15-47-09

You use typed string trigger. I don't think it will work for your purpose.
When you select a text, by typing "<>", you are replacing the selection with "<>", then "copy" will not copy what you selected. Replace the trigger with a hotkey trigger and try again (I did not have a trigger in my macro above because I'm using Palette trigger).

That is correct. I made an assumption that you either copied it or knew how to insert the copy command. I was addressing your Insert Text action.

Ah, I see. That makes sense. Thank you.