use AppleScript version "2.4"
use scripting additions
set inst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
set var1 to system attribute ("KMPARAM_Variable_1")
set val1 to system attribute ("KMPARAM_Value_1")
set var2 to system attribute ("KMPARAM_Variable_2")
set val2 to system attribute ("KMPARAM_Value_2")
set var3 to system attribute ("KMPARAM_Variable_3")
set val3 to system attribute ("KMPARAM_Value_3")
set var4 to system attribute ("KMPARAM_Variable_4")
set val4 to system attribute ("KMPARAM_Value_4")
set var5 to system attribute ("KMPARAM_Variable_5")
set val5 to system attribute ("KMPARAM_Value_5")
setvariable var1 instance inst to val1
setvariable var2 instance inst to val2
setvariable var3 instance inst to val3
setvariable var4 instance inst to val4
setvariable var5 instance inst to val5
end tell
Well Neil, this is the result I get with your test:
so that seems OK.
The only thing I would suggest (but may be totally irrelevant since it's working for me as-is) is this: since your plug in is just setting values having a timeout is completely unnecessary so I'd set the Timeout number to 0 in your Keyboard Maestro Action.plist file.
Another thing - and this is what I call "best practice" - to avoid confusion with anyone else's plug ins I always preface the name of mine with my initials "TFL". Of course, this is just a convention I've adopted but at least it makes identifying plug ins in the actions list that much easier and ensures there's no clash of names in the future. For example, on my system I have:
Weird. It's working for me too now. Very odd, as I'd tried dozens of times and even restarted my mac during testing. Now it just works. Gift horse / mouth etc.
The default timeout for KM actions is 99hrs, so I figured it should be something more than 0. Guess not. Thanks!
Thanks for your input. The only problem is that the number of variables is limited to 5. It's nice if the macro needs to set 5 variables (no more, no less).
For sure, @tiffle's approach is much more efficient if you're setting short variable values. I mainly had a go at this alternative approach for the opportunity to develop my plugin-making skills.
That said, it's actually very easy to adjust the plugin to increase the number of variables if you wish, by editing the .plist and .scpt files in the plugin folder.
The main advantage of this plugin is that each variable has its own text box, so if your values are a little longer, it's still relatively readable.
Five seemed to be a number just large enough to justify using a plugin rather than native actions in order to save vertical space, without being so large that it would begin to defeat the object by bloating the macro.
You can of course use multiple of these plugin actions if for some reason you're setting a lot of explicit variables at the same point in your macro which, for me personally, doesn't come up that often.
I tried to find a way to programmatically generate the plugin XML with user-defined variable numbers, but it seems like a non-starter. It would be cool if there was a way to add a + button to a plugin to dynamically create new fields, but I don't think that's possible either.
The plist defines the user interface for the plug in action and I havenât discovered a method of dynamically changing it while in the KM Editor. I donât know enough about the ins and outs of Mac software development to definitively say itâs possible or not - maybe @peternlewis can shed some light on this?
You can't have variants of the plugin installed, so that does not seem like it is going to work.
You could generate the XML for the action, set of actions or whatever. For example, given a list of variables, you could generate the XML for the Group action or a For Each action that dealt with all the variables any way you wanted. The XML could even indicate that the root level action was un-disclosed.
Is it possible provide an option to suppress the popup for the Prompt for User Input action?
This option could be added to the right click menu (see below). I can then use the default value field to set values for multiple variables in one action.
Of course, the problem is that if a pop up window is suppressed then it is no longer a pop up window. So maybe a new action can be added that works similar to the Prompt for User Input action but without the popup feature. When the variables values are simple (e.g., numbers or consisting of a few characters/words), this action will be very useful.
I'm afraid I don't have any plans to do either of these.
It doesn't really make sense to have a variant of the Prompt for User Input action that doesn't actually prompt but does set all the variables.
And I don't see enough value in an action to set a bunch of variables to values that exceeds simply using a sequence of Set Variable to Text actions (optionally within Group action).
Especially when there are a variety of other ways that it could be done, such as passing a multiline block of text to a subroutine or a Favorite action that sets all the variables.
Hey Peter, I replicated this for my personal use, but it doesnât seem to work when I want to set the variables to %Delete%... what am I doing wrong here?