MACRO DEMONSTRATIONS
⌃F2 : Insert Below; Display Text; Short Value(s)
Video
⌃⇧F2 : Insert Below; Prompt for User Input; Short Value(s)
Video
⌃F2 Tapped Thrice : Prompt With List menu displayed with the eight options selectable
Video
⌃F2 Tapped Twice : Repeat previous option
Video
PURPOSE
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
- Filter
- 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 using a Display Text or Prompt for User Input action.**
- ⌘: Add the action Below or Above the selected actions.
local_ShortValueA [%Variable%local_ShortValueA%]
local_ShortValueB [%Variable%local_ShortValueB%]
local_LongerValueA
┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈
%Variable%local_LongerValueA%
local_LongerValueB
┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈
%Variable%local_LongerValueB%
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 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.
CALLING THIS MACRO
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.
RELATED INFORMATION & ACKNOWLEDGEMENTS
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.
TESTED WITH
• Keyboard Maestro 10.2
• Ventura beta 13.3 (22E5236f)/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445
VERSION HISTORY
Click to expand/collapse
1.0 - Initial version
1.1
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
2.0
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.
3.0
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
**3.1
**a) Extracts target variables in the Filter action.
b) Extracts capture group variables in the Search using Regular Expression action.
3.2
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.
4.0
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.
4.1
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).
4.2
a) When macro completes, the initially selected actions are reselected (thanks to some guidance from @ccstone).
b) Updated the TESTED WITH information.
4.3
a) Bug fix: Previous versions would capture variable values that were not variables (i.e., not \%Variable\%.+\%).
b) Updated the TESTED WITH information.
Download: Insert Action to Check Variable(s).kmmacros (208 KB)
Macro-Notes
- 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.
System Information
- macOS 13.3 (22E5236f) PRE-RELEASE SEED SOFTWARE
- Keyboard Maestro v10.2
MACRO MENU
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.
EXAMPLE ACTIONS CREATED BY THIS MACRO
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.