Help with Making Macro that Uses Clipboard Text to Find and Trigger Macro with Same Words in Title

I'm having a problem making a macro for work, and I'd really appreciate some help figuring this out. What I'd like to do is have me highlight a word(s) with my mouse and trigger the macro that does these tasks:

  1. Copy the word(s) to the clipboard.
  2. Remove all spaces.
  3. Lowercase all letters.
  4. Search for a macro with the same name as the words (now without spaces) in the clipboard.
  5. Activate that macro with the matching title.

For example, after I highlight the words "Target audience" and trigger the macro, it will remove the space between the two words, make all the letters lowercase, look up the macro titled "targetaudience," and activate it. (If you're wondering why I want to remove the spaces, it's so I don't have to be so concerned about accidentally highlighting an extra space before and/or after the word(s).

This is all I have so far. I can't seem to find the other steps I need.

1 Like

Now that you have the text formatted the way you want, are you looking for the execute a macro action?

For all other actions -> Actions [Keyboard Maestro Wiki]

Thank you for the links. Do you know how to use the clipboard data to tell KM which macro to trigger?

This is how I'd go about solving this problem:

Example Macro.kmmacros (3.2 KB)

This may go without saying, but be warned that with this method, you may not have to worry about excess whitespace, but any typos or spelling errors in the macro name copied will of course result in the target macro failing to execute.


Nice! I like @gglick's approach. Reading through How to call a KM macro from a shell or Perl script I learn that Keyboard Maestro gives you example scripts for different kind of script triggers for different languages. You can then use those inside Keyboard Maestro to call Keyboard Maestro macros dynamically. :exploding_head:

Screenshot of where macro shows how to call macro by script language

Then I tried it myself but using the shell script action and it worked!!!! So cool!

I created a simple alert Macro with a name that I copied into my clipboard...

Screenshot of alert macro

Then I ran my own macro that calls a macro dynamically based on the contents of the clipboard and it worked!

Screenshot of clipboard macro calling macro

Thanks for joining the forum and asking a great question!

Help with Making Macro that Uses Clipboard Text to Find and Trigger Macro with Same Words in Title.kmmacros (45.1 KB)

testalert.kmmacros (44.4 KB)


Thank you for putting that together. It works great! I'm a book editor, and I'm hoping to share this with some colleagues since we constantly use text expansion. By only highlighting, copying, and triggering the macro instead of doing the extra steps of opening a comment, typing the expansion shortcut, and finalizing the comment, it saves a lot of time. (I added steps to open the comment and finalize it.)

Thanks again. I really appreciate it.


I wish I understood what you're macros do. I, unfortunately, didn't learn to code growing up like I probably should have.

1 Like

Very nice! Glad it helped. There is no time like the present to learn what you need to be able to automate more of your job. For me it's a strong motivator to learn more as I try to automate more and more of my work. :wink:

Have a great week! :beers:

1 Like

I guessing that most of us here didn't learn while growing up either! But KM's "building block" approach makes it easy to create usable macros from the start, which you can then add to as you learn more.

All you need is a plan, and the manual so you can look for what you need.

So the plan is:

  1. Copy the selected text
  2. Remove all spaces from the text
  3. Make the text lower case
  4. Run a macro with that spaceless, lower-cased, name

There are many ways to do this -- here's one that implements the plan action for action.

  • Step 1 doesn't need explaining but you might want to check the Wiki page to see what else is possible.
  • Step 2 is a simple search and replace-with-nothing on what was previously copied to the System Clipboard, the only "odd" thing is that I've used the %Space% token to make it obvious what's happening -- you could just type a space in there.
  • Step 3 is the same "Filter" action that @gglick used, changing the text on the clipboard to all lower case.
  • Step 4 uses the "Open URL" action to run the appropriate macro, using another text token ("%SystemClipboard%") to use what's on the clipboard as the "macro name" parameter of the URL.

Run Macro From Text.kmmacros (2.3 KB)


@gglick After getting Typinator, I decided to make a new macro that was built a bit on yours. I want this mainly to use in Microsoft Word. What it does is copy the text, open a new comment, types the text without spaces (normally with a prefix), the typed text triggers the text expander entry in whichever software the user is using, and the comment is finalized after the comment has been pasted.

Automated Comment Using Text Expander Software.kmmacros (10.1 KB)

Many editors use a ton of macros that are specifically designed for editing in Word, but I'm hoping to slowly make macros in KM that will allow me to have similar functionality in Google Docs and Wordpress. I met one other book editor who uses KM, so maybe we might work together to help other editors be more efficient. BTW, if anyone is interested in seeing what macros editors use in Word, you can find a collection of hundreds of them here.