Can I pick a variable dynamically, using a variable?

Hey Jack,

I'm not clear on what you mean.

Your action shows you placing a text-token for a variable name in a variable name field.

No can do.

You cannot use a variable to set the variable portion of the Prompt for User Input action.

If you really need to do this you could:

  • Export the action to disk.
  • Open it in a text editor and extract the text between the outermost <dict>…</dict> tags.

You can find/replace on the myVariable string and change it to anything you want.

set myUserInputAction to text 2 thru -1 of "
<dict>
  <key>Buttons</key>
  <array>
    <dict>
      <key>Button</key>
      <string>OK</string>
    </dict>
    <dict>
      <key>Button</key>
      <string>Cancel</string>
      <key>Cancel</key>
      <true/>
    </dict>
  </array>
  <key>IsActive</key>
  <true/>
  <key>IsDisclosed</key>
  <true/>
  <key>MacroActionType</key>
  <string>PromptForUserInput</string>
  <key>Prompt</key>
  <string>Please enter the details for these variables.</string>
  <key>TimeOutAbortsMacro</key>
  <true/>
  <key>Title</key>
  <string>Test Do Script</string>
  <key>Variables</key>
  <array>
    <dict>
      <key>Default</key>
      <string></string>
      <key>Variable</key>
      <string>myVariable</string>
    </dict>
  </array>
</dict>
"

tell application "Keyboard Maestro Engine"
  do script myUserInputAction
end tell

This is a bit cumbersome, but it's very powerful.

-Chris

2 Likes