Using Script Debugger with Keyboard Maestro

Is there a way for an AppleScript to "reach into" KM to extract some variables using "getvariable" and have it reflected in KM when the AppleScript performs a "setvariable"?

Moving back and forth between SD and KM turns out to be a real pain.

You'll have to use global variables for testing and change them after the fact.

You can also have KM run your AppleScript from a script file, so you can just save in SD and run from KM (but you still have the global/local variable issue).

There are a couple of macros on the forum that let you find/replace variable names in the selected macro.

One by @JMichaelTX and I think one by @cdthomer (I may have missed a couple of others), but the King Daddy of them is VIP by @DanThomas.

MACRO: Variable Inspector Prompt and Dictionary Editor v3.2

1 Like

Thanks, but still a pain. I'm looking to execute an AppleScript using data from KM. But of course, SD doesn't have the KM runtime present when you're trying to execute the AS. So, of course, you can do it KM, when you have all the KM global data available, but then you give up the debugging capability of SD. Hope that's clear.

You can run your AppleScript in SD, and that script can reference KM global variables -- why can't you use the debugger in SD? And since SD is itself scriptable you could go even further and use KM AppleScript actions to drive SD.

The main problem (apart from some non-trivial work, obvs!) would seem to be having to use global variables -- and even that might be avoided if you drive SD from within the KM macro you are testing, because you'll have the "KMINSTANCE" system attribute and that can give you access to local variables.

1 Like

Yes, it's a pain.

I thought I covered everything else with:

By using global variables in Keyboard Maestro you can easily access them in Script Debugger and then after testing you can change them to global variables.

However – I think Nige's excellent idea to use the instance has the fewest downsides.

  • Set a global variable to %ExecutingInstance%.
  • Run your macro with a pause in the appropriate place.
  • Then you can run your script in SD and work with variables from the macro.
tell application "Keyboard Maestro Engine"
   set kmInstance to getvariable "kmInstanceVar"
   set myVar to getvariable "local_MyVar" instance kmInstance
end tell
1 Like

I understand. Thanks.

1 Like