I have an AppleScript-based application that I have set a cron job to run every 15 minutes. This part works perfectly. However, when the script opens, it pauses and waits for user interaction. Sometimes I put it off, and by the time the next 15 minutes rolls around, a second instance opens.
What I’d like to have happen is: when the app launches, it checks to see if another instance is already running, brings that instance to the front, and quits itself. Conversely, it could quit the one that’s already running and bring itself to the front. Either way, I’d wind up with a single instance of the application as the frontmost window.
Right now, the closest I’ve come is:
As you can probably guess, this quits the current instance of the app, even if no previous instance is running; and if a previous instance has somehow managed to remain open, the new instance doesn’t interact with the previous one.
So, bottom line: how can I check for another instance of the same script that’s doing the checking, and operate on that?
Thanks!
What I’d like to have happen is: when the app launches, it checks to see if another instance is already running, brings that instance to the front, and quits itself. Conversely, it could quit the one that’s already running and bring itself to the front. Either way, I’d wind up with a single instance of the application as the frontmost window.
Right now, the closest I’ve come is:
Code:
tell application "System Events" to set previousScript to (name of processes) contains "[I]the app name[/I].app"
if previousScript is true then
tell application "[I]the app name[/I]" to activate
return false
end if
As you can probably guess, this quits the current instance of the app, even if no previous instance is running; and if a previous instance has somehow managed to remain open, the new instance doesn’t interact with the previous one.
So, bottom line: how can I check for another instance of the same script that’s doing the checking, and operate on that?
Thanks!