Accessing local variables in Applescript when run asynchronously (v11.0)

Never tried this before so not sure if this is a bug or just something that isn't possible. I have a script that runs several macros via Applescript in a ForEach loop. If I set the applescript to run with "Ignore Results" it works fine. However, if I set it to run asynchronously the scripts don't execute at all. The line where I do a getvariable to retrieve a the value of a variable from the current instance returns an empty string.

Attached is a slimmed down example (the disabled actions where me verifying my scripts could actually run asynchronously directly, they do). When run as is, the dialog that shows the instance id and the macroID will correctly show the instance id but the macroid is an empty string.

I can see this being caused by the time the Applescript has actually launched the main macro itself has ended so the Local variables no longer exist (i tried using Instance_ variables too but the same issue would apply, the main macro has ended so no Instance variables available).

If this is the case then I wonder if I accomplish this by putting a semaphore lock before launching the applescript, then doing an unlock in the launched applescript.

Test Execute Macro.kmmacros (5.5 KB)

Both test scripts I'm running do the same thing: pop up a window showing the start time of the script and the name of the script.

Couldn't get it to work with semaphore locks, but a simple pause after executing the script to give the script time to launch and retrieve the variable value works. Worked on my mac (MacBook Pro with M1 Pro chip) with a pause of .2 seconds but I set to .25 seconds for a bit of breathing room. .1 seconds made it so only the last script in the list executed.

Note that this time isn't dependent on how long the macro executed by the script takes, just the time for the Execute Applescript action takes to launch the Applescript and have it retrieve the local variable value. This is only really worth it if you're launching macros that take a long time to run, if the macros are fast probably not worth the extra effort.