Shorter (nicer) KM code?

Is there a shorter (direct) way to code something like:


I’m not sure what you are actually asking for here, but you might be able to write more compact statements using an Execute Script Action with either AppleScript or JXA. Both of these have full access to KM Variables and tokens.

It is 2 actions in a macro called by an Execute a Macro Action with a parameter.

%Triggervalue% is the name of the variable (the parameter) I have to set to the result %Variable%safaric__contents%

It works, but is a unique pure KM action (no AppleScript) does exist for the same job?

You are welcome.

Sorry, but I don’t understand your question, or what you are trying to achieve.
Can you please provide more details.

Sorry to be unclear. I just mean one KM action in place of two to set variable of name %TriggerValue% with the result.

BTW as I have experienced the token %TriggerValue% cannot be processed inside an Execute AppleScript Action because the running context is not (yet :wink: ) transmitted to osascript.

So an intermediate Set Variable to Text Action is needed to process %TriggerValue% token…

If I am understanding you correctly, you are passing the KM Variable name as the parameter in the Execute Macro Action, like this:

If you want to just read/use the value of the Variable, then put the Variable token in the Parameter block, like this:

Does this make sense to you?

To avoid misunderstanding, some commented test code:
Testing Macros.kmmacros (4.4 KB)

Thank you JMichael for your patience.


@alain, did I understand you correctly? Here are two macros that show this process:

The key is using the Variable token, rather than just the Variable name, in the Parameter block:

###Main Macro


###Results Shown by Sub-Macro

Does this now make sense, or are you trying to do something else?

BTW, you could even use/display the `%TriggerValue% without setting a variable to it:

JMichael, that I do is not your post #8 nor the #9 but just that the “indirect addressing” of #7 no more: the calling macro send variable name not variable value :wink:

OK, I have reread your posts, and now I think I understand.

Correct me if I'm wrong, but Is this what you want to do:

  1. Pass a Variable name in Parameter block of a Execute Macro
  2. Have the sub-macro set that variable to some value.

After some experimentation, this seems to work:
In the Sub-Macro, put this in the "Set variable" block:

###Main Macro


###Results Displayed by Main Macro

Yes, assuming that your objective is:

I just posted the complete macro with example main macro:

Isn’t that just:

  • Set Variable “%TriggerValue%” to text “%Variable%safaric_contents%”?

Unless you actually want the safaric_param variable set to the parameter name too, in which case you’re setting two variables, so I’m not sure how it would be any shorter.

Yep, same thing I was saying:

@JMichaelTX Correct :slight_smile:

@JMichaelTX, @peternlewis By this mean, I can easily choose the (unique) name of (global) KM variables to avoid conflict calling generic sub macros.

I was stupidly inhibited to put a token in an action variable field :blush: but I am very happy it already works.

Thanks for your help.