Upfront, I’ve only used this on Pre-Mavericks systems, so please feel free to chime-in with results on Yosemite and friends.
Very often when running either Stay-Open scripts, or long-running scripts with complex operations, it can sometimes become necessary to be able to exert control over them.
Often, this takes the shape of periodic interrupts that bring up dialogs enabling some gear-shifting, or quit via our good old friend:
error number -128
So why no “System Events” / “Killall” commands?
Well because Applescript applications all show up to ps -ax as “applet”. This is fine if you only use that one AS app, but I usually have 7 or more running. Also, if you use an NSUIelement in the Info.plist to hide them from the Dock, they cannot be force-quit in the usual way (this ‘hiding’ is often desirable, as the system’s ‘Focus’ will jump to a stay open app every time it cycles - this sucks if the return number is say every 5 seconds).
Well there is a bit of TomHackery to the rescue.
Within the application bundle you will find the applet executable (/Contents/MacOS/applet). The cool thing is that you can elect to simply call it something else! Like myApp or whatever (this does not need a file-extension. Don’t add one, or it won’t work).
Next, we have to aim the application toward the new item. In the Info.plist (/Contents/Info.plist), you can simply change the applet under CFBundleExecutable to the new name so it would then look like:
CFBundleExecutable
myApp
Then you want to Re-copy the application bundle to a new location (ideally with option+copy) and then it will now use the new executable.
The benefit is you can now use a ps -ax | grep to to detect the app and stop it with a simple:
do shell script "killall myApp"
Also, should it be needed, the new app-name can be used to Re-Nice your custom app if higher executable priority is needed.
P.S. Just realized I forget to mention that you should also rename the .rsrc file to the chosen new name. It can be found at (/Contents/Resources/). If you don’t rename this too, will always bring up the “Run” or “Quit” dialog. Sorry - has been a while since writing one of these!