MACRO: Insert Action to Check Accessed Variables, v2.0

QUICK START

  • Select an action within another macro.
  • Press the primary hot key [ ⌃F3 ] for this macro. A group of actions will be inserted below the selected macro action.
  • In the other macro, select one or more actions above the inserted group.
  • Run the other macro.
  • When the other macro executes the inserted group, a window will be displayed that includes the values for variables within the selected actions.

PURPOSE

Used during macro development and simple debugging, when triggered, this macro will add a macro group that includes actions that will display macro variables values (per the %AccessedVariables% token and various specified options).

The macro has eight different triggers that are all combinations of three options:

  1. ⌘: Display variables for the selected action(s) or all actions above.
  2. ⌥: Display variables and pause or display and continue.
  3. ⇧: Insert the group below or above the selected action(s).

If display and pause is selected, a dialog will be displayed with three buttons:

1. Close Window & Continue : the %AccessedVariables% window will be closed and the macro will continue; can be specified by pressing the return key.

2. Continue : the %AccessedVariables% window will remain open and the macro will continue; can be specified by pressing the c key.

3. Cancel : the macro exits; can be specified using the esc key.

The primary trigger for this macro is ⌃F3. It, or any of the other seven hot key combinations, can be tapped once, twice, or thrice. If tapped once, a Display Text action will be inserted below the selected action(s).

Mode 2: If ⌃F3 is tapped twice, the previously used trigger (one of the eight) will be effectively repeated. This provides a quick method to insert several identical th macro groups throughout a macro.

Mode 3: If ⌃F3 is tapped thrice, a Prompt With List menu will be displayed with the eight options selectable:

⌃F3 : Insert Below; Display Variables and Pause; Selected

⌃⌘F3 : Insert Below; Display Variables and Pause; All

⌃⌥F3 : Insert Below; Display Variables and Continue; Selected

⌃⌥⌘F3 : Insert Below; Display Variables and Continue; All

⌃⇧F3 : Insert Above; Display Variables and Pause; Selected

⌃⇧⌘F3 : Insert Above; Display Variables and Pause; All

⌃⌥⇧F3 : Insert Above; Display Variables and Continue; Selected

⌃⌥⇧⌘F3 : Insert Below; Display Variables and Continue; All

When the PWL menu is rendered, each option will be labeled with the corresponding trigger. This provides a quick reference to the eight options.


GROUP OPTIONS

As stated above, this macro inserts a group of actions that has options to display macro variables. Two of the options selected|all and pause|continue are set based on the trigger used to execute this macro. All of the options can be changed after the group is inserted. The options are as follows:

Control [ :red_circle: Display Variables ] Groups? (Select One)

  • Disable (This Group)
  • Disable (This and Subsequent Groups)
  • :heavy_check_mark:︎Display Variables and Pause (This Group)
  • Display Variables and Pause (This and Subsequent Groups)
  • Display Variables and Continue (This Group)
  • Display Variables and Continue (This and Subsequent Groups)

Control—Permit Override? (Enable or Disable Yes)

  • :heavy_check_mark:︎Yes

Selected Actions Only? (Enable or Disable Yes)

  • :heavy_check_mark:︎Yes

Exclude Unchanged Variables? (Enable or Disable Yes)

  • :heavy_check_mark:︎Yes

Exclude Empty Variables? (Enable or Disable Yes)

  • :heavy_check_mark:︎Yes

Exclusions (comma separated RegEx patterns specifying variables to exclude)

  • :heavy_check_mark:︎Reset Button

Optional Window Title

  • :heavy_check_mark:︎:red_circle: Display Variables - # -, where # is a counter

The checkmarks (:heavy_check_mark:︎) above indicate the options that are set if the group is inserted using the primary hot key for this macro–⌃F3.


MACRO SETTING

local_VariableCharacterCountThreshold : 55 [default]

If an accessed variables value is one line and less than local_VariableCharacterCountThreshold characters, then the variable will be displayed as follows:

:o: local_A [%Variable%local_A%]

If an accessed variables value is one line and greater than or equal to local_VariableCharacterCountThreshold characters, then the variable will be displayed as follows:

:o: local_B
[%Variable%local_B%]

If an accessed variables value is more than one line, then the variable will be displayed as follows:

:o: local_C
%Variable%local_C%


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

• Thanks to @noisneil for feedback and testing prior to the release of this macro. He suggested the method used to present and select the options within the group.

• The multi-tap detection is done using the amazing HotKey Multi-Press Template, by @DanThomas.

Insert Action to Check Accessed Variables largely supersedes a macro I previously created and shared, Insert Action to Check Variable(s); it creates the variable list by parsing the XML of the actions that are selected when the macro is invoked. In most respects, this macro is superior, but Insert Action to Check Variable(s) might be of some value to those with interest in this topic.

• When inspecting variables within a macro, another very useful macro is Variable Inspector Prompt and Dictionary Editor, by @DanThomas.

• For full-featured debugging of macros, I recommend: Checkpoint System: An Additional Way to Debug in KM, by @tiffle.


TESTED WITH

• Keyboard Maestro 10.2
• Ventura beta 13.4.1 (22F82)/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445


VERSION HISTORY

( expand / collapse )

1.0 - Initial version

1.1 - Fixed a few typographical errors in this header and in the macro group that is inserted.

2.0
a) For binary settings, simplified each by using a default value of Yes. To change one of these binary settings, the Yes action is disabled. (Previously, for these binary settings, one action had to be disabled and one had to be enabled.)
b) Changed the name of some of the settings to better describe the purposes.
c) Bug fix: In previous versions, Exclude Unchanged Variables? was effectively Yes regardless of the setting.
d) When the group does not have any variables to report (based on the specified settings), the messages have been improved to provide more specific explanations.
e) Streamlined some of the group logic.



Download: Insert Action to Check Accessed Variables.kmmacros (745 KB)

Macro-Image


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.4.1 (22F82)
  • Keyboard Maestro v10.2


OPTIONAL MAIN MENU

5 Likes

Example use of Insert Action to Check Accessed Variables.


The macro below originally had the top four actions. With all four selected, or just the fourth, the Teal group is added using the primary hot key trigger [ ⌃F3 ] of Insert Action to Check Accessed Variables.


When the above macro is run (with the four actions selected), the following is generated by the Teal group.


The behavior of the Teal group can be optionally modified by expanding it and changing the included options.

Keyboard Maestro Export

2 Likes

I've updated the OP with Version 2.0 of Insert Action to Check Accessed Variables:

  • For binary settings, simplified each by using a default value of Yes. To change one of these binary settings, the Yes action is disabled. (Previously, for these binary settings, one action had to be disabled and one had to be enabled.)

  • Changed the name of some of the settings to better describe the purposes.

  • Bug fix: In previous versions, Exclude Unchanged Variables? was effectively Yes regardless of the setting.

  • When the group does not have any variables to report (based on the specified settings), the messages have been improved to provide more specific explanations.

  • Streamlined some of the group logic.

  • Updated the TESTED WITH section.


Maybe you've passed over this thread because it seems overly complicated. :flushed: I don't blame you!

In practice, I've gotten 90% of the benefit with a simpler approach.

There are three combinations of settings (all mentioned above) that I use frequently; so I've saved these groups to my Favorites (Actions > Add to Favorites).

Then when I need to insert one, I just use the wonderful Insert Action by Name feature of Keyboard Maestro (Edit > Insert Action > By Name...). If you haven't done so already, do yourself a big favor and memorize this keyboard shortcut: ⌃⌘A


Below are the three groups that I've added to my Favorites. The states of three key settings (Unselected, Unchanged, Empty) are indicated in the group names. The first group (1 :green_circle: ✓Unselected; ✓Unchanged; ✓Empty) will display the most information; the last group (3 :red_circle: xUnselected; xUnchanged; xEmpty) will display the least.

To add these to your Favorites, open a new empty macro, import the three groups, and then use Actions > Add to Favorites to add each.

Then when you want to use one, just press ⌃⌘A.


Group.kmactions (144 KB)

Keyboard Maestro Export


Group.kmactions (144 KB)

Keyboard Maestro Export


Group.kmactions (143 KB)

Keyboard Maestro Export

1 Like