Getting Macro Depth for Dynamic Logging Indentation

Lots of my macros are calling other macros and it's great.

The problem comes when I need to troubleshoot an issue, so I added logging with this action:

Keyboard Maestro Export

• The '\t' ensures the line stands out from the normal KM logs
• It uses %ExecutingThisMacro% instead of %ExecutingMacro% so the macro the log action appears in will be referenced
• 'Start' can really be anything, but here I'm just denoting the start of the macro

After using that in a bunch of places, now my KM Engine Log looks like this:

What I like about this is there is the tab I put in to separate the KM logs from my own logs. It's a good start, but I would like to take it a step further.

Every time I call a macro from another macro, I would like my log to use another '\t' in the prefix. Of course when the macro returns, I want there to be 1 less '\t'.

How can I keep track of this? I thought about modifying the tab count manually at the start and end of every macro, but I'm not excited about the overhead of doing that every time I write a macro.

Essentially what I need is a way to check the current depth of a particular macro. Any ideas?

Hi @kraftyDevil,

This may or may not be of interest to you and addresses your question in a roundabout way.

Some time ago I released a utility tool that I developed to help me with debugging complicated macros. It consists of a few plugin actions and some helper macros. In use it does quite a lot of things including showing a “breadcrumb trail” of nested macro calls - much as you are asking about.

Because it addresses a lot more than just your immediate question, you might find it overkill.

Anyway, you can read about it here and also download the full user manual there:

1 Like