Macro: Demo Use of Trigger "Keys" (Parameters) in Trigger by Name

###Macro: Demo Use of Trigger "Keys" (Parameters) in Trigger by Name
###MACRO:   Test TK

~~~ VER: 1.0    2017-05-24 ~~~

####DOWNLOAD:
Test TK.kmmacros (11 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


###Use Case

  • Allow passing of a parameter (trigger key) when using the KM Trigger_Macro_by_Name action (KM Wiki).
  • Format: MyMacroName MyTriggerKey
  • Examples:
    • timer 10
    • test tk key3
  • The macro can detect the parameter/key, and take appropriate action.
  • Allows you to have one base macro with a variety of options that can be chosen using the Trigger Macro by Name macro.
  • This demo macro also shows you how to get all of the KM Trigger related data.

###Example Results

####Trigger by Name Prompt

####Key Found

####Key NOT Found


###ReleaseNotes

Author.@JMichaelTX
• Based on macro by @PeterNLewis.
• Thanks, Peter and @mthorton for a great concept! :+1:

PURPOSE:

  • Demo How to Use Trigger Keys (Parameters) with Trigger by Name

NOTICE: This macro/script is just an Example

  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

HOW TO USE:

  1. Invoke the "Trigger by Name" Action/Macro
  2. Type the Full Name of this Macro + SPACE + a valid Trigger Key
  • For Example: "test tk key3"
  1. As long as you type the Macro Name, plus optionally any character KM finds in the Macro, you can trigger the Macro.

MACRO SETUP

  • 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. :wink:
      .
  • Assign a Trigger to this maro. I prefer TBD.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • SET VAR: List of Valid TRIGGER KEYS Typed at End of Macro Name

TAGS: @Trigger @Name @TriggerKey @Demo @Example

USER SETTINGS:

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

ACTION COLOR CODES

  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Variables or Clipboards,
    OR IF/THEN and PAUSE Actions

REQUIRES:

  1. Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
  2. El Capitan 10.11.6+
  • It make work with Yosemite, but I make no guarantees.

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

5 Likes

With the current version of Keyboard Maestro, isn't there a way to pass a parameter?

Passing Parameters

You can pass parameters (v8+) to the macro via the %TriggerValue% token by adding // and then the parameter to your search string. The // and anything after that will be ignored in the search.

Or have I misunderstood the documentation?

1 Like

Yes.

See Execute a Macro action