I have been grappling with a problem and discovered that instance variables are not behaving as described in the KM wiki manual:Variables [Keyboard Maestro Wiki].
The wiki says:
"[Instance Variable] Available to the Macro where it was created and Sub-Macros of that Macro, for a given execution instance of the main macro"
and
"for example, if you execute a macro using the Execute Macro action, that macro can see and change the instance variable"
However, if the submacro is executed asynchronously the instance variable no longer behaves like that. Instead, the scope of the instance variable is restricted to the calling macro and does not encompass the asynchronous submacro.
Here are a couple of macros I used to demonstrate this:
[Test] Macros.kmmacros (3.1 KB)
The first macro sets up an instance variable and then asynchronously executes a submacro after which it displays the value of the instance variable.
The submacro displays the value of the instance variable and then changes its value and exits.
The first macro ends up displaying the value it set up initially - which might actually be valid if the first macro finishes before the submacro has time to change the instance variable's value.
The submacro, however, displays an empty value for the instance variable - meaning it is out of scope.
I can imagine this behaviour is possibly what might be reasonably expected so can @peternlewis confirm this please? If it is intended behaviour, can you please update the wiki before someone else uses up time discovering this?
Personally, I would much prefer if instance variables were in scope of both the calling macro and any submacros it executes asynchronously (or not).
Thanks!