Is it Possible to pass a variable into the Trigger by Name Macro?

Hello Folks!
I need a little help from you. I have a mcName variable that I'd like to automatically populate and search within the Trigger Macro by Name action. I've searched and tried different methods but nothing, that I was able to find in the forum, worked. I'm able to use variables in my other macros. I'm thinking there is something special or unique going on while using this action. Please assist.

Thanks so much.


I'd like the variable to populate here.


This is the action that I'm using. I've placed a pause and an insert by typing %Variable%mcName% to no avail. I'm sure it's me.

Don't think it is you... this looks like a bug where the variable token is not being passed to the initial search field on run.

1 Like

@kcwhat, I can confirm this behavior, whether a bug or by design.

@peternlewis can confirm.

I'd suggest you try this great macro:
MACRO: Execute Macro by Name (Spotlight) by @DanThomas

1 Like

Thank you for your response. I appreciate you taking the time to check this out.

Thank you JMichaelTX for verifying and responding to this. I was trying all the methods I thought I learned before asking. I will check out the DanT's macro.

Thanks again!

It is not a bug, per se, simply lacking a feature, which is already done for the next version:

  • Trigger Macro by Name initial search now processes tokens.
2 Likes

Wonderful. Thanks for the confirmation and adding the future feature.

KC

Thank you for fixing this! :slight_smile:

Is it possible to change location of the Trigger Macro by Name window? Can it be centered?

Thanks,
Kenneth

No.

It is centred horizontally, but higher up vertically.

Thanks. I took another route. The window was behind a palette so I used the Conceal Macro Palettes action to begin before the window appears. Once done, I used the Reveal Macros Palettes Action to reset it.

The last thing on this subject (for now) is once I pass the variable to the Trigger Macro by Name window, is it possible to automate the return key to enter in that window? I've tried the Return Keystroke action and AppleScript System Events Return script to know avail.

I just want to pass the variable to the Trigger Macro by Name and Enter without my interaction.

Is this a preventative measure?

Thanks,
KC

I don't understand - if you know the macro you want to execute and the trigger value you want to send, why are you using the window at all? Why not just execute macro directly via AppleScript?

Peter,

Why? Because I was laser focused on the wrong path of just working with the Trigger by Macro Action. I’m not a programmer or scripter. I admit that I’m just flailing in the wind sometimes. For many of my solutions, I know that there has to be better or more efficient ways of using techniques. Thanks for the suggestion. When I get home, I will do research on how this can be done. Hopefully, it’s just a matter of:
tell “Keyboard Maestro Engine”
do script “mcName”
end tell
.... or somehow grabbing the UUID from the mcName. I have two wiki pages that I will focus on. I’m sure I can figure it out or ask the right question. Funny how when you asked the question, lightbulbs started going off.

Any other suggestions or techniques are appreciated.

Thanks,
KC

Ok. I have been defeated this time. I've been on so many Forum pages that I've confused myself. I'm asking for help.

I have a KM variable called (mcName). I'd like to pass that mcName variable to AppleScript do script. Yep, I looked at a few AppleScript pages on here and my syntax/format is jacked.

I'd like to this in the Execute AppleScript action:

tell "Keyboard Maestro Engine"
 do script "[my mcName Variable]"
end tell

The current value for the mcName Variable is MegaMillions. This MegaMillions macro happens to be a global macro that runs from anywhere.

However, it didn't work, because the variable didn't pass through.

So I went down the rabbit hole, saw a post from Peter (a version 7 post I think) and did this:

tell application "Keyboard Maestro Engine" 
set myNam to getvariable "mcName"
do script myNam
end tell

NOPE. Didn't work. I'll spare the 20 or so variations and a few hours. Now, I'll humbly ask for help.

Please put me out of my misery. Can you explain how to do this? I promise not to ask for help for another 2 weeks or so. :slight_smile:

Thanks,
KC

that should have worked, provided that the KM Variable "mcName" is defined AND has the name of a valid macro.

So, from the macro action area, where you assign a trigger, there is dropdown labeled "Or by AppleScript". For example:

tell application "Keyboard Maestro Engine"
   do script "Use One Image to Find Another [Example]"
end tell

You might check your actual macro in this area to confirm the name.

Try this macro. It will display an error if "mcName" is NOT defined.

tell application "Keyboard Maestro Engine"
  set myNam to getvariable "mcName"
  
  if (myNam ≠ "") then
    do script myNam
  else
    
    set currentApp to path to frontmost application as text
    tell application currentApp
      set msgStr to "INVALID Macro Name"
      set msgTitleStr to "Trigger Macro via AppleScript"
      display dialog msgStr with title msgTitleStr ¬
        with icon stop
    end tell
    
    
  end if
  
end tell
1 Like

Thanks for your time JMichaelTX. I quit the engine and restarted it. Miraculously, it worked. I used your macro as well. No errors came up and it worked fine as well. I'm still scratching my head though because I'm not confident why it worked. Maybe something triggered with the drop down "Or by AppleScript" area. Doesn't make much sense.

Something weird happened though. At first it was just plain text, but then it compiled (You know, with the formatting and colors). After that, it worked.... (shrug).

In two weeks, I'll ask how to properly syntax this one as well but for a single macro with the mcName variable:

tell application "Keyboard Maestro Engine"
set enabled of macro group "Macro Group Group Name or UID" to true/false
end tell

However, you helped with the other one so I can wait until my probationary period is up! Plus my head hurts from this ordeal.

Thanks so much as usual Sir!

KC

1 Like