I have a main app which launches one or more copies of helper apps stored in the .app/Contents/Helpers/ folder. The apps are launched with the following code:
Window1.helpers() as Shell
Window1.LaunchHelpers
const numberHelperApps = 8
for i as integer = 1 to numberHelperApps
dim cmd as string = "env FLAGS=-foobar" + str(i) + " open -gn " + appFile.shellPath
dim sh as new shell
sh.mode = 1
sh.Execute cmd
helpers.append sh // keep a reference so the shell never goes out of scope and gets destroyed
next
This has worked well for years across multiple macOS versions. Suddently, in Big Sur, it’s inconsistent - sometimes I get 8 helpers launched, sometimes 7, 6, 4 or even just one.
However, if I run the equivalent command in Terminal:
for i in {1..8}; do echo $i; open -gn MyApp.app/Contents/Helpers/MyHelper.app ; done
my actual code is using the & operator in the shell commend, e.g. open -gn MyApp.app/Contents/Helpers/MyHelper.app &
and I’m also using mode 1 (asynchronous) shells.
So my theory is that perhaps in Big Sur, the command open -gn if run quickly enough, is not detecting the very first launch of the app (the “-n” option means “open a new instance even if it’s running”. The “&” in the shell command means “run this command in the background, don’t wait for it to finish”
Setting the Shell to mode 0 (synchronous) and removing the background “&” from the command seems to fix the problem, at some cost in slower launch time for the main app.