"Execute an AppleScript" option "Execute variable script"?

Just curious why there's no option to execute an AppleScript or JXA or whatever from the contents of a KM variable? Something like:

...then execute it?

You might ask why I would want something like that, since we can pass KM variables into scripts. Well, I want to do this:

tell application "System Events" to tell process "Keyboard Maestro" to get exists text field 1 of sheet 1 of window "Keyboard Maestro Editor"

but I want to supply different paths. So I need an AppleScript something like this (not real code):

-- get KM variable into _script
return run script _script

which is an extra level of indirection that is necessary.

Like I said, I just wonder why.

Sorry, Dan, but I don't see the need.

What's wrong with this:

It's the last line "return run script _script". It runs the script specified in the variable. That's the extra level of indirection.

Sorry, I don’t see the issue/problem.

Subject to the usual question marks about evals (a little doubtful about them myself, as it happens) the two script idioms both provide for them:

applescript: run script strScript (if memory serves me)

JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

@JMichaelTX also:

It’s not a big issue. It’s a small issue. Question, really. And apparently I can’t explain it very well. And since all of this is true, then “never mind”.

But thanks for playing!

this works fine for me:

So, what else would you want?

1 Like
  1. Right now, I can create an AppleScript file on disk. I can say to KM “Here, run this”.

  2. I can put an AppleScript into the Action text box and say to KM “Here, run this”.

  3. Why can’t I create an AppleScript in code, in a KM variable, and say to KM “Here run this”?

I can, as you pointed out, do the following:

  1. Build an AppleScript in code.
  2. Tell KM to run an AppleScript which I also built, which when it runs…
  3. Says to KM “OK, now give me the script I built”.
  4. My AppleScript code then runs the script I built in step 1.

And yes, it ends up doing pretty-much the same thing. But why have to go through those steps? Does it work? Of course it does.

I’m just saying it’s extra work, technically takes longer to run, and also requires knowledge that you can do a “run script” from AppleScript, which I had to do Google searches to find.

That’s what else I would want.

A very, very, small amount of extra work, and, IMO, a low number of use cases.
What we have now works very well. I see no reason to spend scarce resources to further automate something that takes you only a few seconds to do. Using two actions vs one is trivial.

Basically because there cannot be an action for every possible case. In this case, the extra action is exactly this:

Execute AppleScript:
tell application "Keyboard Maestro Engine" to run script (getvariable "Source")

For everything I add to Keyboard Maestro I balance a bunch of factors:

  • How much does it gain
  • to how many
  • how much complexity will it add
  • how much time will it take to implement

For this case, the “how much does it gain” is quite small since there is already a simple solution, and the “to how many” is quite small as well.

1 Like

Thanks, Peter. That’s all I really wanted to know.

Hey Dan,

I prefer Peter's solution for this, but just for reasonable completeness:

Generic-Test 01.kmmacros (1.9 KB)



Boy, I sure haven’t been able to explain this to anyone, have I?

Sigh. It really doesn’t matter - it’s not happening either way.