Simple Text Expansion macro

In light of Text Expander’s recent announcement, I’m getting a lot of requests about how to create a simple text expansion in Keyboard Maestro.

If you haven't created a macro yet, first read the Quick Start and do the Tutorial (Help ➤ Tutorial). This will teach you the terminology used in Keyboard Maestro, and show you how to create a simple macro.

To create a simple text expansion in Keyboard Maestro, create a macro group to hold them by clicking on the + button at the bottom of the left hand column and naming it something appropriate like Text Expansions.

With it selected, create your new macro by clicking on the + button at the bottom of the second column and name the macro.

Click the top green + button to add a Typed String trigger, and then set the trigger text appropriately (eg =ww=). It is important to ensure you wont accidentally trigger the macro so I like to include an equal sign on either side of my triggers, but whatever works for you and that you wont accidentally type in the middle of some other word will work.

Click the green + New Action button. In the Text category, double click the Insert Text by typing action. Type in the desired expansion text in the resulting action.

That's it, you're done and it's live.

To create more, you can just select the first macro and Command-D Edit ➤ Duplicate it, and then adjust the name, trigger text and expansion text.

Here is an example:

=ww=.kmmacros (1.6 KB)

4 Likes

Update: *Using Insert Text by Pasting seems to do the trick

While using KM to expand snippets, the expansion occasionally and randomly inserts extra returns or misplaces spaces. Is there a way to correct this misbehavior?

For example, I entered a simple replacement three times in a row and got three different responses:

fil etype:pdf
filetype:pd f 
file type:pdf

If you type quickly, and you type during the expansion, your typed text will be interspersed with the expansion, so that may be what you are seeing.

For this reason it’s generally a good idea to include the space at the end of the expansion if you expect to be typing it within a sentence. This is because people then to type the space after a word very quickly and then have a longer gap after the space before typing the next word.

1 Like

I’m so over TextExpander and the issues I’ve been having with formatting and inserting a linked URL into a snippet. Is this something that I can do with KM?

Probably. It depends on how you format the linked URL.

I don’t recognize the term “snippet” in the context of KM. What are you trying to do? If you are trying to (ultimately) insert an actual link into something like a Mail message or TextEdit document I can tell you how to do that.

In TextExpander (TE), you can create a formatted snippet to store things like a rich-text hyperlink (like KM Forum). Since KM variables can only store plain text, the only way I know to store rich-text is in a Named Clipboard.

However, I just discovered that you can "Insert Styled Text by Pasting":

To get this KM Action, goto KM Editor > Actions > Text > Insert Text by Pasting.

Then change the popup to "Insert Styled Text by Pasting"

So you could use this KM Action in a text-expansion Macro.
You would have to create the rich-text hyperlink in another app, or in another KM Macro, and then paste into the above Action.

Here is a complex Macro that creates rich-text hyperlinks:
Macro: Set Clipboard to RTF Hyperlink & Plain Text MD Link

It may be more complex than you need, but you could use parts of it, include the script that actually creates the hyperlink, in a much simpler macro.

Hope this helps. Please feel free to ask any follow-up questions.