TIP: How To Determine if Macro is Used a Sub-Macro, Called by a Execute Macro Action

Use Case

  • AFAIK, KM does NOT provide a direct means of determining when a Macro is called via a Execute a Macro action, aka a "Sub-Macro"
  • So if a Macro could be used directly (i.e. executed by a trigger), OR it could be used as a Sub-Macro, how can we tell how it is being used?
  • After some limited testing, it appears to me that:

IF a Macro is triggered directly, THEN:

  • The %ExecutingMacro% token will be the SAME as the %ExecutingThisMacro% token.
  • The %TriggerValue% will be based on the actual trigger

ELSE IF a Macro is Called via "Execute Macro" Action, aka "Sub-Macro", THEN:

  • The %ExecutingMacro% token will be DIFFERENT from the %ExecutingThisMacro% token.
  • The %TriggerValue% will be the PARAMETER as entered on the Execute Macro Action.

@peternlewis, would you please confirm or correct this assertion?

Assuming this is correct, here is a Macro that shows how to use this information.
It is a Macro that can be used in either mode (Direct or Sub-Macro).

Example Output

Trigger Tokens When Used as a Sub-Macro

Trigger Tokens When Used Directly (Triggered by a HotKey)

image

MACRO:   Trigger Tokens in a Sub-Macro (called by Execute Macro)

**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:
<a class="attachment" href="/uploads/default/original/3X/8/3/83f58d1a320a7826f651430693f00343472933cb.kmmacros">Trigger Tokens in a Sub-Macro (called by Execute Macro).kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


---


<img src="/uploads/default/original/3X/d/6/d698101ce026afc3b2cdaa1d2bdfebe55b613337.png" width="592" height="1942">

`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`


### MACRO:&nbsp;&nbsp;&nbsp;MAIN Macro to Call Sub-Macro To Get Trigger Info [Example]

~~~ VER: 1.0&nbsp;&nbsp;&nbsp;&nbsp;2020-01-05 ~~~
**Requires: KM 8.2.4+&nbsp;&nbsp;&nbsp;macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/c/9/c94e043436c37226ed027dc943f57f153714e8ea.kmmacros">MAIN Macro to Call Sub-Macro To Get Trigger Info [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


---


<img src="/uploads/default/original/3X/0/6/0699047eefa9b789eb2f8ffc0305d02211bedb06.png" width="592" height="416">

It is correct, except the last line:

  • The %TriggerValue% will be the PARAMETER as entered on the Execute Macro Action.

The %TriggerValue% will be the PARAMETER as entered on the Execute Macro Action if it uses a parameter. Otherwise (if the Execute Macro action does not include a parameter) the %TriggerValue% will be inherited from whatever it was in the parent macro.

Thanks for the clarification, but I DID say "the PARAMETER ==as entered== on the Execute Macro Action"

So, I believe my statement is correct as written. :wink:
It just did not cover the case where the parameter is not entered.