Hi KM community,
I'm just fiddeling around with a macro that should configure an application that I use often (but does not save its layout). I move the main window and do some clicking in it... nothing special. I'd like to have this happen in two (trigger-)cases, though:
Whenever I start the app (trigger application launches)
As a subroutine with parameters (e.g. window position)
So here's my question: Is it possible to add parameters to the subroutine triggers but give them default values if the parameters are not available (e.g. the macro is triggered by another trigger) and (only) in these cases use these?
I actually know a functionality like that from PHP functions where you can just write something like
function dosomething($var1, $var2, $var3 = 'somevalue'){
// Rest of function here...
}
In this example var3 would be optional as it has a default value which will be used if it is not set in the function's call.
If there is no simple way, any ideas how to workaround the problem (other than copy the whole macro for each trigger and maintain both versions in parallel)?
Sure. You can add an If/Else for each variable at the start of your subroutine. If the variable is empty, set it to something. Here's an example from my Prompt With List... on Steroids macro.
Sorry for replying much slower than you did... and thanks for your solution! Quite simple solution for the "optional parameter problem" I had.
I tried it in my environment and since I combined it with the application launches trigger, I had one more problem to solve: My application-setup of course needed the application to run and if not to start it but this would trigger the same macro again. It worked though to just use the deactivate macro group action for the corresponding macro group before the "activate MyApp" and activate it again afterwards.
I wonder why there is no deactivate macro (or trigger) action but just the groups? Maybe for safety to keep macros from reactivating manually deactivated macros... but the (de-)activate Macro Group action does not even allow a token/variable like %executingMacroGroup%. No problem to hardcode the Macro group in, but as soon as I put the macro into another group it won't act as it should anymore... we'll see when that might happen.