Used during macro editing and simple ad hoc debugging, when triggered, this macro will add an action to display all macro variables in the selected actions. For example, the following Keyboard Maestro Actions (and many others) often include one or more 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 (actions within are also queried)
- 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 Variables and pause or display and continue.
- ⇧: Add the action Below or Above the selected actions.
local_ShortValueB [%Variable%local_ShortValueB%] local_LongerValueA ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ %Variable%local_LongerValueA% local_LongerValueB ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ %Variable%local_LongerValueB%
If display and pause is selected, a dialog will be displayed with three buttons:
Continue : the variable window will remain open and the macro will continue; can be specified by pressing the return key.
Close Window and Continue : the variable window will be closed and the macro will continue; can be specified by pressing the c key.
Cancel : the macro exits; can be specified using the ESC key.
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 actions using the format: local_ShortValue [%Variable%local_ShortValue%]
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 Variable(s) and Pause; Short Value(s) ⌃⌘F2 : Insert Below; Display Variable(s) and Pause; Longer Value(s) ⌃⌥F2 : Insert Below; Display Variable(s) and Continue; Short Value(s) ⌃⌥⌘F2 : Insert Below; Display Variable(s) and Continue; Longer Value(s) ⌃⇧F2 : Insert Above; Display Variable(s) and Pause; Short Value(s) ⌃⇧⌘F2 : Insert Above; Display Variable(s) and Pause; Longer Value(s) ⌃⌥⇧F2 : Insert Above; Display Variable(s) and Continue; Short Value(s) ⌃⌥⇧⌘F2 : Insert Above; Display Variable(s) and Continue; 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.
Variables are presented in the order they are found within the XML of the actions. Many times this order differs from the order that the variables appear within the actions (in the KM Editor).
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 selected actions.
• 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 13.3.1 (22E261)/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445
Click to 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 Execute a Subroutine action.
b) Simplified error dialogs by using OK/ and ︎Cancel Macro.
c) Fixed typos in this header comment.
a) Multiple actions (contiguous or otherwise) can now be selected and queried.
b) After the new action is created, it is selected in the editor.
a) In the AppleScripts that add the new action, disabled Failure Aborts Macro.
b) In several actions (If Then Else, Switch/Case, While, Until, Pause Until) extracts the object when it is a calculation (e.g., local_B when local_A = local_B).
a) When macro completes, the initially selected actions are reselected (thanks to some guidance from @ccstone).
b) Updated the TESTED WITH information.
a) Bug fix: Previous versions would capture text values that were not variables (i.e., not \%Variable\%.+\%).
b) Updated the TESTED WITH information.
a) Bug fix: Since v4.1, captured all calculated objects as a single variable. For example, a simple calculated object of 100 would incorrectly be assumed to be a variable.
b) Captures multiple variables within a calculated object, e.g., (local_ABC + instance_XYZ) / local_JKL.
c) For the triggers, changed the modifiers: 1) ⌘: Display format for Short Values or Longer Values, 2) ⌥: Display Variables and continue or display and pause, 3) ⇧: Add the action Below or Above the selected actions. Previously, the order was ⌥, ⇧, ⌘
d) Changed the display and pause to use a Display Text action and a Pause for User Input action.
e) Added the KNOWN LIMITATIONS section in this header comment.
f) Updated the TESTED WITH information.
a) Variables within calculated objects are now captured
b) Sets the size and position of the Display Text windows. As new windows appear, they are slightly offset on the x-axis.
c) Window include a title which includes the Window Number.
d) Plays the medium-volume Bottle sound after the action is inserted.
e) Optimized the search of XML for the variables.
a) Changed the default to Display Variable(s) and Pause.
b) Corrected a typographical errors in this header Comment and the Prompt With List.
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
- macOS 13.3.1 (22E261)
- Keyboard Maestro v10.2