Action Doesn't Work if Executed as Sub-Macro

I'm confused. I have a Search and Replace action in a macro. If I execute the macro, the action works. If I call that same macro from another macro via an Execute Macro action, then the Search and Replace action doesn't work.

The red action in this macro is the one in question. If I directly run the macro via the Run button or the hotkey in the app, all the Search and Replace actions run as expected. But...

...If I call the same macro here (again, in red), it does not fire the red action (leaving a blank line at the start of every file processed).

What do I need to do to make this work? I did try putting a pause in the first (sub) macro of up to 5 seconds, but that had no difference.

Hey Pariah,

Hmm... Me too.  :sunglasses:

It's hard to decipher everything you're doing, but I have a couple of ideas.

Why are you using one or more named clipboards?
β €β €- Generally variables are better for text and temporary storage?

Named clipboards are piped through the main system clipboard, so they can create unexpected mischief.

You know you're searching for \r\n – yes?

That's a Windows convention, and I've seen it be problematic when written as such.

The way you've written the regular expression will remove all consecutive sequences of those two characters it finds and nothing else.

What exactly are you trying to remove?

I've occasionally seen EOL characters get weird when moved between apps via the clipboard.

You may also in your testing have gotten bitten by this little gem:

Sometimes Problematic Issue with Display Text in Window Action v1.00.kmmacros (6.6 KB)

Install and run the macro.

Note the output in the KM display window.

Paste the clipboard into BBEdit or TextEdit.

Note the difference.


In my opinion it is vitally important to be able to turn OFF the trim function in the Display-Text-in-Window action.

People will continue to get bitten by this one.

I was debugging some text replacements a while back and having FITS, because it wasn't working – until I figured out that the display window was eating my whitespace.

Last but not least – create the smallest test case you can and try to repeat your problem. Debug it if possible – if you can't then post it here, and we'll take a swing.


Whatever your issue is, you are barking up the wrong tree if you think it is related to whether you are running the macro directly or via the Execute a Macro action. To easily see this, instead of running the macro directly, select the Execute a Macro action and click Try, it will do the same thing as running the macro (unless your macro actually depends on the selection in Keyboard Maestro).

Your issue, whatever it is, is because you are getting different clipboard results depending on other factors in your macro.

If you are trying to deal with different forms of line endings, then I would strongly encourage that you use the Filter action to filter your clipboard to a specific line ending format first.

This is not really true.

Anything that copies or pastes to/from an application goes via the system clipboard. This is true regardless of whether you use variables or Named Clipboards - if you copy test from an application, it goes in to the system clipboard first, and to paste text to an application, it has to go in to the system clipboard first.

But you can, for example, copy between two named clipboards, or filter a named clipboard, or search & replace a named clipboard, and none of that will touch the system clipboard.

Displaying text is for displaying text, it is not a way to debug the exact context of a variable or named clipboard.

If you want to do that, enclose it in quotes:


Yes. The issue being seen is related to the interaction between the two macros, not the fact that one is run via Execute Macro action.

Also, remember that you can see the value of variables and named clipboards in the Keyboard Maestro preferences.

I should have mentioned that. I did try Try before I posted. I used Try alone and also Try the red action and the preceding clipboard-related actions together. Try was NOT executing the sub macro exactly the way the same sub macro operated with Run.

Now that I try to screen record both in action, neither is working correctly. This may be related to the other technical issues I've been experiencing with KM that you and I have been corresponding about Peter, or, in my attempts to troubleshoot those more urgent problems, I might have inadvertently done something that broke this one.

I'll look into that.

That wasn't working for me either. I tried many different methods, including several other regular expressions. The only thing that worked on this one line was \r\n. I'm open to suggestion, of course.

Here's my code, also attached, that I'm converting from Windows-exported M3U to TXT.

#EXTINF:3,HHH divider - ------------------ SUNDAY
M:\Music\Support\Clips - Organizers\Day - 01 ------------------ SUNDAY.mp3
#EXTINF:200,David Bowie - Changes (Live)
M:\Music\LIVE\David Bowie\David Bowie - Changes (Live).mp3
#EXTINF:202,Cheap Trick - I Want You to Want Me (Live at the Forum, Los Angeles, CA - December 1979)


Day - 01 ------------------ SUNDAY 
David Bowie - Changes 
Cheap Trick - I Want You to Want Me (Live at the Forum, Los Angeles, CA - December 1979) 

HHH Short Form Playlist CleanUp.kmmacros (8.9 KB) m3u and (2.2 KB)

Instead of \r\n, you might try \R, which will match ALL forms of new line, including \r\n.

1 Like

Hey Peter,

I'd forgotten about the quote trick – thank you for reminding me.

I don't quite agree with you about this though.

Display Text in a Window is for displaying text the user has designated to be displayed.

Adulterating such text without warning the user this will happen and without giving them a proper option to turn off trimming is heavy handed.

As far as I can see this issue is not documented on the Wiki page for the action.

The Display Clipboard action also silently trims text – as does the Value Inspector window.

The Execute Shell Script, AppleScript, JavaScript, JXA, and Swift Script actions all have the capability to turn off β€œTrim Results” in the action's gear menu and contextual menu.

It is not unreasonable to expect that Display Text in a Window and Display Clipboard would also have this very basic capability.

These are the primary mechanisms by which users eyeball and interact with their data in Keyboard Maestro – particularly when building macros and debugging them.

I'm not the only user who has pulled his hair out, because display-text was showing him/her unexpected results.

I truly think you ought to reconsider your position on this one.

Regardless of what you decide, it would be good if the trim-feature (or change thereof) was documented in the Wiki.


1 Like

Thanks, @JMichaelTX, but that put all the text on a single line. I need something that's going to remove just that first line, which is originally #EXTM3U but after a replacement of (?m)^\#.* becomes a blank line by itself.

It doesn't seem to help.

Filtering to Unix line endings gives the same results: blank line at top not replaced by later \r\n , \n\n, etc. actions

Filtering to Mac line endings, and searching for \r\r yields the same result: blank line at top, other lines processed correctly.

I resolved it. I just added an action to remove #EXTM3U\n ahead of any other filters. I don't know why didn't try it earlier... Maybe I did. Troubleshooting too many things at once, I think.

Thank you all for your help.

@iampariah, that's probably because you used a RegEx that matched too much.

Here's my solution which uses \R where appropriate.
There is one issue which I am investigating: Why is the last line converted to all lower case?
I think this may be a bug, but it could be a bug in my RegEx.

Example Output

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.


Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.


MACRO:   Remove Unwanted Text from String [Example]

UPDATED: 2021-02-01 19:04 GMT-6

  • Turn OFF Text Processing in SourceStr to prevent unwanted conversion to lower case

-~~~ VER: 1.1    2021-02-01 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Remove Unwanted Text from String [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.




  • Remove Unwanted Text from String [Example]
    • This uses a series of Search/Replace using RegEx


  1. First, make sure you have followed instructions in the Macro Setup below.
  2. Trigger this macro.


  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??

Make These Changes to this Macro

  1. Assign a Trigger to this macro.
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro, and the Macro Group it is in.
    (all shown in the magenta color)
    • SET Source String


  1. KM 9.0+ (may work in KM 8.2+ in some cases)
  2. macOS 10.11.6 (El Capitan)+

TAGS: @RegEx @Search @Replace @Strings @Example


  • Any Action in magenta color is designed to be changed by end-user