How To Create a 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)


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.


These instructions are excellent. I was looking at TextExpander and the like, and now I realize I can build these expansions right into KM!

Personally I prefer to just trigger most of these from the status menu rather than having to remember a bunch of codes.

These are also so easy to create/maintain within KM. Great solution!


Hey Michael,

Don't do that unless you have a very few. Use a Prompt With List
to allow easy discovery of hundreds or even thousands of items.

You can even set it up, so you can add custom tags to the insertion text.


1 Like

Chris - The prompt with list option looks interesting, but what would the potential issues be with using the menu?

Cumbersome to use.

I don't have a lot of snippets but if I had over 50 it might become so.

I have almost 50K...

So I use Typinator instead of Keyboard Maestro for snippets.


Typinator looks great. I'll keep it in mind!

Even after your passing, you're still helping people! Thanks @JMichaelTX


I give up. How do I get a simple text snippet to work? I thought this would be immediately straightforward. I just want to type, "rr" and have it replaced in any application text field with my email text. What am I doing wrong? Thanks.


Your macro is good.

Things to check:

Is the macro group enabled?
Is the macro in the Global Macro group area or a group in which All Applications are available?

Screen Shot 2021-11-27 at 10.34.02 PM

1 Like

Hey Russell,

And it should be.

  • What version of macOS are you using?
  • What version of Keyboard Maestro?

There have been a lot of folks with permissions problems on later versions of macOS due to Apple's negligence.



Thanks for the response, @kcwhat. It's in the Global Macro Group and the group is enabled and available in all applications. I've heard lots of problems with later OSs so I'm still using Mac OS 10.15.7 (Catalina).

Oh wait, it magically seemed to start work with no discernible change. I don't understand, but I will ask a follow-up question related to this message I got, if that's ok:

Neither KeyboardMaestro nor the KeyboardMaestro Engine are listed in my Privacy & Security-->Privacy-->Screen Recording apps and there doesn't seem to be a way to add them. They are both listed and active under the "Accessibility" option however.

That’s what @ccstone was angling at. Go ahead and add Keyboard Maestro and Keyboard Maestro Engine app to screen recording as well.

See this post:

1 Like