How to Know if a Macro Is Used as Sub-Macro Somewhere?

I've been playing with KM for a while and to keep things in order and reusable I've created several macros to be used as submacros.
Everything is fine but, now that I've reached a stable state, I'd like to delete those macros that I don't use as submacro anymore.
But... I'm not sure if a macro is actually used as submacro somewhere or not.
Is there a way to know that so that I can avoid to delete a macro that is used as submacro?

View > Sort

Screen Shot 2021-04-01 at 4.28.46 PM

1 Like

Hey Francesco,

Welcome to the forum!   :smile:

There is no convenient way to tell if a macro is used as a sub-macro.

It's generally best to create one or more Sub-Macro Macro Groups to collect them in for this very reason.

As far as I know there is no means to go backwards from a sub-macro to its parent.

You can do a search in the Keyboard Maestro Editor for "Execute Macro" (or create a Smart-Macro-Group).

From there you can copy the XML of each macro using – Edit › Copy as › Copy as XML.

Then you can use any of several methods to search the copied XML for "<string>ExecuteMacro</string>" and use that anchor to discover the name or UUID of the target macro.a

It's cumbersome, but it works – and you can turn the job into a macro.

If @peternlewis would add XML as a property of macros then this sort of thing would be almost trivial. (He says with longing in his heart.)


1 Like

Just to add to this -

Once a Macro is targeted as a Sub Routine it can be moved to a different Group and it is still found and executed by its Parent Macro.

So... this means you can do good housekeeping and put the Sub Routine Macros into Sub-Macro Macro Groups even after all the Macros have been made.

1 Like

Thanks @hello,
I could wait a week or so so that sort by Use Count or Date Used returns meaningful results (right now I've used all of them several times), and then narrow down the items for a manual search. That could work.


Thanks @ccstone and @Zabobon,
but even if I group the submacros in specific groups I wouldn't be able to see if they are actually used or not.
The search option, by the way, is interesting.
Even just searching for the macro name (without involving the XML stuff) could be enough.

I'm thinking of a macro that:

  1. takes a string in input
  2. looks for that string inside the other macros
  3. returns a list of the macros found

I don't know yet how to do point 2 and 3, and I don't even know if I can execute a macro B on macro A (so that macro B can get the name of macro A and do the search) so... long way to go :slight_smile:
But I'll try.


Huge apologies if I am showing something you already know:

  1. Use @ccstone's suggestion to make a Smart Group to find all Macros that are calling for Sub-Macros. This will list all the Macros that are actively using Sub-Macros.


  1. Open each Macro in the list. Click on the name of the Sub-Macro and move the mouse to the right. That will reveal a hidden option to go straight to that Macro.
    You can move that Sub-Macro into a new Group, rename it to make it clear it is needed, and/or add in a Comment Action to say the same. All things that will make it easier to find in the future - including making a Smart Group to list Used Sub-Macros.

I am thinking in my own case, going forward, of putting in a Comment Action into my Sub-Macros which lists the Macros that use them.

I have been trying this idea and it seems to work well. To make the process quicker I add the comment first to the Parent Macro (that way I can copy and paste its name) than Cut that Comment Action, go to the Sub-Macro and paste in the comment. Feels like this could be automated by a Keyboard Maestro Macro... or even better, Keyboard Maestro did something like this all by itself.

Okay. I have found something interesting. The problem with my idea of putting in a Comment saying what Master Macro the Sub-Macro is linked to is, what happens if the name of the Master Macro changes or it is moved to a different Group?

What is needed is a dynamic bit of information in the Sub-Macro that changes if the Master Macro is renamed or moved. And this can be achieved with a workaround if the Sub Macro includes an Action to Execute the Master Macro and that Action is left in a disabled state. Then the Master and the Sub are dynamically linked and the info upates if one of both of them are either renamed of moved.

This is the Master Macro with its active Execute Macro Action:

This is the Sub-Macro with its disabled Execute Macro Action - which is acting as a dynamic link just to show the name and location of the Master Macro.

This is definitely a "workaround" only as it could cause big problems of circular loops (if the Action in the Sub-Macro is not disabled) but it shows Keyboard Maestro can do this - i.e. know what the Master Macro the Sub is linked to. I am wondering how hard it would be to have this done automatically each time a Sub Macro is incorporated via the Execute Macro Action?

This would neatly answer @magobaol's original question without needing lots of searches etc.

Hi @Zabobon.

There is an issue with this approach: if the Sub Macro is executed from another Master Macro as well, then you'd need to include a second disabled Execute Macro action inside the Sub Macro that shows it is also executed from Master Macro 2!

If, like me, you have sub macros that are called by many other "master" macros this would get very unwieldy.

Yes, absolutely. It is not a solution at all. I was just interested that "reverse" links from the Sub-Macro back to the Master-Macro are possible as they can already be done by this workaround. And "reverse" links would be very useful for finding redundant Sub-Macros as in @magobaol's original question at the start of this thread.

1 Like
  • Edit the sub-macro.
  • Add “FINDME” to the end of its name.
  • Command-F
  • Command-F (a second one forces the All Macros group to be selected)
  • Type FINDME [return]

Thank you @peternlewis. That is kind of what I was suggesting at first (although I was adding different text to the end of the Sub-Macro's name).

But that won't help find Sub-Macros in the Library that are no longer needed and can be safely deleted as @magobaol was asking. The only way to do that is by trial and error.

I suppose it is not too serious having redundant Sub-Macros as they probably use up such a tiny amount of the Macro Library's data? But for housekeeping it would be nice to be able to identify ones that just aren't used by any other Macro.

I love the way you have implemented the Execute Macro Action so that it keeps track of the Sub-Macro even if its location or name changes. That makes the whole system very robust.

I also think keeping things as simple as possible is probably good practice. In other words, having sections of Macro's having duplicate Actions rather than calling on Sub-Macros for everything feels easier to manage. At one stage if I had three Actions in a row, that I found I was using for several similar Macros, I would make those three Actions into a Sub-Macro and call it from each Macro. But I quickly found my Library became confusing. So, now I tend to just paste the same three Actions into each of the Macros. That way I can delete redundant Macros without worrying they are going to mess up other Macros.

Just to add one method that might be helpful.

We can use, e.g., -use:54w, to search for macros that are not used in the last 54 weeks.

From wiki:

For the created:, modified:, used:, the parameter is a number followed by a letter (s for seconds, m for minutes, h for hours, d for days, or w for weeks).

You can use a negative sign (-) to negate any match (for example, “-name:PDF”).

manual:Search Strings [Keyboard Maestro Wiki]