@pete31 By chance, does your script sometimes mistakenly open apps when it’s checking to see if they’re running?
The reason I ask is that I made a script that I run through Alfred and feed to other apps, like DEVONthink (which I think I might have mentioned to you previously) that has this problem. After restarting or shutting down my computer, the first time I run the script, it always does this - opening some of the apps that are not running, though it ultimately still grabs the correct file path, etc. After it’s run once, however, it works perfectly fine. It’s super annoying!
In any case, my code’s a little different from yours, so I was considering checking if the app is running by converting over to your approach, assuming it doesn’t have this problem. FWIW - While I’m no programmer, I think it’s related to the way that applescripts are compiled (whatever that means), which I’ve seen others complain about elsewhere.
If you’re curious, here’s how my script starts:
global frontApp, frontAppName, windowTitle
set windowTitle to ""
tell application "System Events"
set frontApp to first application process whose frontmost is true
set frontAppName to name of frontApp
end tell
if frontAppName is equal to "Adobe Illustrator" then ... [TONS of apps, etc.]
Thanks for your help!