A macro to copy text following an operator, how?

Hi,
Suppose that i need to type a text “$XY” where XY is a NOT a fixed string that follows the operator $. How I can define such a thing. The idea is to define a variable so that the text following the operator is copied to clipboard and then some action is done with it. An example is:

Hey Katy,

Your example didn’t come through.

Please provide more info.

-Chris

1 Like

If I understand your question/need correctly, you should be able to achieve this using a macro with a typed string trigger, where the typed string is a RegEx pattern.

Maybe something like this:

\$.+\$

That will trigger the macro with any text string that starts and ends with a $ symbol.

See the macro I just posted for an example:

Without your example, it is hard to know for sure, but if the text you want to type is in the clipboard, then you can do:

Insert Text by Typing "$%CurrentClipboard%"

or if it was in a variable, you can do:

Insert Text by Typing "$%Variable%VarName%"

Thanks for that. In fact JMichaelTX1d answer is what I am looking for. But I wonder if it is possible with only a sting only at the start. Say I want to write a macro for word ‘Temperature’ that is triggered by typing $temp, would that work instead of $temp$? I am trying to build a macro that is slightly more complex than that for automating physical constants and scientific jargons containing various european characters.

Thanks

Hi Peter, Sorry, I do not want to rely on clipboard but the variable thing may work. Could you please explain that a bit more as I am not familiar with how to use variables.

Hey Katy,

You can be as simple or as sophisticated as you want to be with typed triggers.

Typed Trigger Example.kmmacros (1.4 KB)

This looks for the literal string '$temp' and then emplaces the expanded text when you type a space or a tab.

If was looking to mnemonically manage temperature I'd probably use a non-regex string like:

tmp;
or
;tmp
or
$tmp
or
°°

Most of my typed-trigger macros use a trailing space, and some use a trailing delimiter character along with a space:

ch<space>  == Christopher
cs<space>  == Christopher Stone
bb<space>  == BBEdit
bb;<space> == Bare Bones Software

Occasionally I'll use a prefix delimiter instead of a suffix delimiter:

;cmd  == ⌘
;opt  == ⌥
;ctrl == ⌃
;sh   == ⇧

My chief concerns for typed-triggers are:

  • Easy to remember.
  • Easy to type.

Remember that you have many options with type-triggers:

-Chris

Katy,

Yes, you can have a typed string trigger of ONLY "$temp".

The reason I used a termination character (like the backslash) is because of the variable nature of what you might type. The backslash tells the KM RegEx engine that you are finished with your string.

But if it is a fixed string, like "$temp", then you can use any string you like. You should have to be careful to not use a string for a trigger that you might want in actual text.

That's why I begin ALL of my text expansions (typed string triggers) with a semicolon (";").

Your Typed String trigger can be whatever you want. “$temp” is fine.

Trigger: Typed String trigger “$temp” delete 5 characters
Action: Insert Text by Typing “Temperature”

The only need for a trailing character comes when you might accidentally type something else, or if you have multiple similar Typed String triggers (such as “$te” for teacher and “$temp” for temperature, where the first one would trigger before you got to type the “mp”).

Was there something else you were trying to do?