The last step of a Macro I have is this:
It's great, but the problem is that the variables that i use persist (I title them instance_variableA, instance_variableB, instance_variableC etc).
A workaround is to nullify each variable by setting making them empty, but that makes my macros bloated. (I have done a search and I found some threads about using an AppleScript, but i also read that Peter disavowed it so I shan't use it..)
I want to be able to "repeat" this macro while my computer is unattended. If i'm there I can just invoke it again manually (once it has run) and the "instance_x" variables are all cleared.
There probably isn't an elegant way of doing this, but I was wondering if I could do something make KM "think" it's not running the same instance when it repeats? I probably can't ... by definition!
If I understand correctly (it's late ), the instance variables persist because they all belong to your macro, which never terminates because of the "goto" step at the end.
You could get rid of that step and instead call your "Octopus" macro from a new macro, "Run Octopus" ("Execute Octopus" sounds harsh), which would just handle the looping.
Do you have to use instance variables? Are those variables used by any other macro while this one is running? Because if not, you can change them to
local to avoid this issue.
I do because i call multiple macros from Octopus and they stop working when I use local_x
You mean create a second macro whose only step is to call Octopus? I suspect it wouldn't work because KM would treat as one "process"
See what you make of Peter's reply here in a thread about Local vs. Instance Variables.
I think it should work, because every time the macro "Run Octopus" executes the macro "Octopus", that will be a separate instance, with its own instance variables. Forgive me if I don't try a test macro, especially since I think it would be much quicker for you to test with what you have already created.
From the same post by Peter: "Use local variables if you want to use or change the variable restricted to only each execution of the macro in which it is defined". So I think your result when substituting local variables is to be expected.
Without knowing the structure of your macro, I might be barking up the wrong tree, but I would just mention that if you happen to be calling macros within "Octopus", you might consider making them subroutines and passing values using the Execute a Subroutine action.
ooh the subroutine thing with parameters looks really interesting!
I'm reading the wiki now, thanks!
(Does anyone know of any video tutorials that explain how it works? I did a quick search on YouTube but found nothing.)
I tried adding this action:
It says "None". Is that normal? (How do i go about defining or creating a subroutine?)
My understanding is that this will allow me to execute PART of another macro, so i was hoping the dropdown would perhaps let me pick?
The target macro defines the parameters via the Subroutine trigger, and you specify the values for those parameters in this action.
You can only use this action to execute sub-macros that include the Subroutine trigger,
EDIT: oh wait, i need to put this inside the Macro that I want to call?
when the wiki talks about the
target macro does it mean the one that will be called? or the one doing the calling?
It is until you have created any subroutines. Once you have done that, they will appear in the list.
Subroutines are just macros which have a subroutine trigger.
- Let's create a macro that will become our subroutine. Let's name it my_subroutine.
- In the macro's familiar "new trigger" menu, select "subroutine trigger".
Congratulations, the macro "my_subroutine" is now executable as a subroutine.
I'll put together a simple demo.
It's the same as one macro calling (executing) another macro. But if that second macro is a subroutine (remember, an ordinary macro that has a subroutine trigger), the first macro can not merely call it but also pass it a value to use (no need to use a global variable).
And the subroutine can return a value to the macro that called it. Just add a Return Result action at the end of the subroutine whenever you need that.
I don't know which page you are referring to, but "target" would mean the macro that is being called.
As I may have indicated in the forum before (and I certainly have by way of feedback), I am of the opinion that the wiki page about Subroutines makes a straightforward and well executed (we would expect no less!) idea seem a bit arcane when you first read it – but if this post is clear, have a look at it again and I think it will now make sense.
So here is the start of a super-advanced (hmm) calculator macro called my_calculator:
my_calculator executes a subroutine called my_doubler, and passes it the number 10.
Here is the subroutine my_doubler, which expects to receive a parameter value, which will be used for the local variable "number".
my_doubler performs the complex calculation, and returns the result to my_calculator.
my_calculator brings up an alert with the answer.
I'm sure it's obvious that my_calculator could call other subroutines as needed – and that other macros could also be set up to execute my_doubler.
It's all easy and logical – once you know how.