⌃F2 : Insert Below; Display Text; Short Value(s)
⌃⇧F2 : Insert Below; Prompt for User Input; Short Value(s)
⌃F2 Tapped Thrice : Prompt With List menu displayed with the eight options selectable
⌃F2 Tapped Twice : Repeat previous option
Used during macro editing and simple ad hoc debugging, when triggered, this macro will add an action to display all macro variables in a selected action. For example, the following Keyboard Maestro Actions (and many others) often include variables in the parameters:
- Set Variable to Text
- Set Variable to Calculation
- Split Path
- Search using Regular Expression
- If (actions within are also queried)
- Switch/Case (actions within are also queried)
- Execute AppleScript
- Execute Shell Script
- Use Variable
- Pause Until
- Looping Action: Until, While, Repeat, For Each
- Execute a Subroutine
- Group (actions within are queried)
The macro has eight different triggers that are all combinations of three options:
- ⌥: Display format for Short Values or Longer Values.
- ⇧: Display using a Display Text or Prompt for User Input action.
- ⌘: Add the action Below or Above the selected action.
┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈
┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈
The primary trigger for this macro is ⌃F2. It, or any of the other seven, can be tapped once, twice, or thrice. If tapped once, a Display Text action will be inserted below the selected action using the format:
Mode 2: If ⌃F2 is tapped twice, the previously used trigger (one of the eight) will be effectively repeated. This provides a quick method to insert several similar actions.
Mode 3: If ⌃F2 is tapped thrice, a Prompt With List menu will be displayed with the eight options selectable:
- ⌃F2 : Insert Below; Display Text; Short Value(s)
- ⌃⌥F2 : Insert Below; Display Text; Longer Value(s)
- ⌃⇧F2 : Insert Below; Prompt for User Input; Short Value(s)
- ⌃⌥⇧F2 : Insert Below; Prompt for User Input; Longer Value(s)
- ⌃⌘F2 : Insert Above; Display Text; Short Value(s)
- ⌃⌥⌘F2 : Insert Above; Display Text; Longer Value(s)
- ⌃⇧⌘F2 : Insert Above; Prompt for User Input; Short Value(s)
- ⌃⌥⇧⌘F2 : Insert Above; Prompt for User Input; Longer Value(s)
When the PWL menu is rendered, each option will be labelled with the corresponding trigger. This provides a quick reference to the eight options.
If this macro is called from another macro and a Parameter of 2 or 3 is specified, this macro will run in Mode 2 (use Previous Option) or Mode 3 (display PWL Menu of Options), respectively. This provides a method to run the macro in the alternative modes without using the two- and three-tap methods described above.
In a Keyboard Maestro forum thread started by @Sleepy, Various Methods for Displaying KM Variables and Data, @noisneil first suggested a clever technique to insert a Display Text (in window) action; @ccstone subsequently contributed his take on the idea. Stealing shamelessly, I contributed another option: Insert⇨Actions to Display a Macro Variable. Since then, @noisneil created and shared Create Pre-Filled KM Actions.
Insert Action to Check Variable(s) supersedes Insert⇨Actions to Display a Macro Variable. It is faster, includes several more options, and does not require any set-up.
• Thanks to @ccstone for assistance with the AppleScript syntax required to insert a new macro action before or after a selected action.
• The multi-tap detection is done using the amazing HotKey Multi-Press Template, by @DanThomas.
• Duplicates are removed using a JXA script (Remove Dup Items in List [Example]), by @JMichaelTX (RIP).
Insert Action to Check Variable(s) leverages the powerful scripting of the Keyboard Maestro editor features that @peternlewis introduced in KM v8.0. Every time I dig deeper into Keyboard Maestro, I'm amazed by the quality and depth of the application.
Insert Action to Check Variable(s), and the others mentioned above, are handy for simple ad hoc debugging. For true debugging see: Checkpoint System: An Additional Way to Debug in KM, by @tiffle.
• Keyboard Maestro 10.2
• Ventura beta 13.2 (22D7750270d)/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445
expand / collapse
1.0 - Initial version
a) In this comment, added the modifier key that toggles each of the three options. Also changed the order of the options.
b) Improved the name in the third Group action
c) Changed the color of the first Group action
d) Fixed three typos:
• In the name of the first Group action
• In this comment
• In the name of the Comment actions included in the Group actions created by this macro
a) All variables in a selected action are now included in the added action; thus the name of macro was changed to: Insert Action to Check Variable(s)
b) If this macro is called from another macro and a Parameter of 2 or 3 is specified, this macro will run in Mode 2 (use Previous Option) or Mode 3 (display PWL Menu of Options), respectively. This provides a method to run the macro in the alternative modes without using the two- and three-tap methods.
a) Extracts variables that are in action Text fields if they are in the form:%Variable%some_variable%. (Before someone asks: the variables in calculations are not included. And based on this statement by @peternlewis that feature is very unlikely to be added to this macro.)
b) Extracts variables from the Split Path action. In that action, XML variable fields do not include a Variable key. I suspect that other such actions will be found as use of this macro continues.
c) Previously if a variable appeared more than once (e.g., in a Group action), the variable would be repeated. Duplicates are now removed thanks to a JXA script (Remove Dup Items in List [Example]), by @JMichaelTX (RIP).
d) Added a Display Progress action since the macro might run several seconds if a long action is selected (e.g., Group). The progress Title is: Searching for variables in the selected action
a) Extracts target variables in the Filter action.
b) Extracts capture group variables in the Search using Regular Expression action.
a) Extracts target variables in the Execute a Subroutine action.
b) Simplified error dialogs by using OK/ and ︎Cancel Macro.
c) Fixed typos in this header comment.
DOWNLOAD Macro File:
Insert Action to Check Variable(s).kmmacros (187 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.
If ⌃F2, or any of the other seven hot key triggers, are tapped three times (or if this macro is called by another With Parameter = 3), the following menu will appear.
Note: The Insert Below options will likely be used most frequently, however, the Insert Above options can be useful when the selected action is relatively long, e.g., with a Group action. In these cases, the inserted action will be automatically pasted above the selected action, after which it could be selected and moved to a desired position in the macro. Conversely, if an Insert Below option was used when a long action was selected, subsequent repositioning would likely require some inconvenient scrolling down.
The following image includes an example of the four types of Group actions that are created after:
- selecting a macro action that includes two variables (i.e., local_A and local_B), and
- triggering Insert Action to Check Variable(s) (this macro).
Note: The Short Value(s) format (i.e., local_A [%Variable%local_A%]) has the advantage of presenting the variable values is a condensed fashion and is also useful when a value might include leading or trailing whitespace. In contrast, the Longer Value(s) format is useful when a variable value might contain two or more lines.
When the above actions are created, the magenta comment actions are closed. The following image displays the Type 4 Group action with the Comment expanded.
Note: This information can serve as a quick reference. Note that the Comment indicates two Type 4 triggers: ⌃⌥⇧F2 or ⌃⌥⇧⌘F2. The first is for inserting a Type 4 action below the selected action; the second above.