Is there a way to view the values of a select group of variables while debugging? (The equivalent of a "watch" pane in some IDEs) I know I can see all variables and their values from the Preferences dialog, but I have many variables (some from imported macros) and during debugging I usually only need to see a few of them. Using the Preferences variable display I have to jump back and forth within the variable list to find the ones I want. (Yes, there are hacks I could use, like temporarily prefixed the variables I want to see with a space or something, but that approach has problems.)
Well, you can “roll your own”. Create a macro that shows a Prompt, and have it show the variables’ values. When you click OK, have the macro re-show the prompt.
You can see them in the Variables preference pane.
You could create a macro that displays their current values.
You could create some Set Variable to Text actions in the editor, and it will live display their value (the first line anyway)
There is no inspector like you find in some debuggers. It is on the todo list.
I am attempting to do essentially what you recommend here (although in my case I just want to highlight a variable name and then run a macro to display its value).
I am having trouble figuring out how to use the system clipboard token within the display variable value token (last action in attached screenshot). Is there a way of doing this?
First of all, use this format to set the system clipboard to a variable:
When in doubt with any action that has a Text field, use the Insert Token
drop-down menu. You could have used it to get the system clipboard:
If you use the Variable
sub-menu and pick any variable, it'll insert the variable using the proper syntax, and you can just change the variable name:
Now, with all that said, check out Window->Value Inspector
. It's way easier:
Hope that helps.
I like the Value Inspector, but I was trying to figure out a way of displaying a variable value with one keyboard shortcut rather than manually entering a variable name into the value inspector.
I wanted to be able to highlight a variable name like in the "demo" below and then with a keyboard shortcut show its value (macro is below the demo). Kind of stupid in this test case since the value is right there, but useful when the value isn't right there.
I also thought about using your "go to KM variable (spotlight)" macro, but I'm having trouble pasting into that macro's search window.
Looks like the search window is part of "Keyboard Maestro Engine" rather than "Keyboard Maestro" and I can't use the "send to" specification in the simulated keystroke action to send it to the right window. Can you somehow specify the "Keyboard Maestro Engine" as the target?
While the KM Value Inspector is better than nothing, I don't find it very useful for these reasons:
- Does NOT support Local or Instance Variables, and almost all of the Variables I use now are Local or Instance.
- It is too difficult/slow to enter Variables into the Value Inspector, especially if you have a lot of Variables in a Macro you want to observe.
- All Variables are shown in the Value Inspector regardless of which Macro you are trying to debug, and it is slow to remove these Variables one-by-one.
@peternlewis, what we really need to easily and effectively debug our Macros is a debugger that automatically displays ALL Variables in the Macro that is currently running (being debugged), like every other debugger I have ever used, like Script Debugger, Safari JavaScript Debugger, Chrome JavaScript Debugger, and more.
Example of a Good Debugger (SD7) Showing Live View of All Variables
Looking for the same. Value inspector is the one I am using now, but it can only see global variables.
I figured out a solution to my original question. With the macro below, you can select a variable name and then assign a hot key trigger to have a window pop up with the value of that variable.
Nice tool. Thanks for sharing.
Unfortunately it only works for Global Variables.
I rarely use Global Variables these days now that we have Local and Instance Variables that are auto-deleted when the Macro terminates.
This conversation, and the one on %ExecutingInstance% token made me realize you should be able to expand this to support Local and Instance variables from other macros. Perhaps you can incorporate this idea into your macro.
Here's a macro that you can run at anytime and it'll grab the value of different variables, global, local or instance from a running instance. In the original macro to fetch values FROM, set a global variable named DebuggingInstance to the %ExecutingInstance% token. I also set a local variable to hold the macro name for the output, but this isn't required.
Here's the output:
To use this, in the macro you're debugging you need to set a global variable the holds the %ExecutingInstance% token for that macro. The independent variable display macro can take that info, and the names of the variables you want to report on, retrieve the variables with AppleScript and push the values back into the current macro.
Macro: Display variables from another instance
Macro: Example macro to debug
This macro sets the DebuggingInstance global variable to its %ExecutingInstance% token and defines some variables. It pauses 5 minutes to give you time to launch the other display variable macro. It also defines a variable with the name of this macro so it can be retrieved by the display variable macro.
Macro Downloads
I frequently call subroutine macros and if others do this it might be confusing as to which variables the macro can display. This might help.
When you have the ExecutingInstance token of a macro's instance, you can use that token to access Local and Instance variables of that macro. If that macro uses Execute a Macro action to launch a subroutine, the called (subroutine) macro shares Instance variables between the two (purple arrow). Local variables in the called macro are unavailable to either the calling macro, or the display variable macro.
So if the subroutine modifies an Instance variable, the Display Variable will show the update. But if it sets a local variable, Display Variables can't access it.
If you want to access the variables in the subroutine, set the DebuggingInstance in that macro. When you do this, you'll still have access to the Instance variables set in the Calling macro, but not local variables in the Calling macro.
Finally - you could update this macro to support 2 different instance tokens. One from the Calling macro and one from the called macro. Then Display Variables could fetch variables from both macros.