Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 22, 2010, 05:48 AM   #1
the Otter
macrumors member
 
Join Date: Jan 2001
Location: Lafayette, IN
Send a message via AIM to the Otter
Handling Duplicate AppleScripts

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:
Code:
tell application "System Events" to set previousScript to (name of processes) contains "the app name.app"
if previousScript is true then
	tell application "the app name" 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!
__________________
“Aunque el mono se vista de seda, mono se queda.”
the Otter is offline   0 Reply With Quote
Old Dec 22, 2010, 05:53 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Get the script to create a file somewhere at the start and delete it at the end. Check for the existence of that file and quit if it already exists.
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
applescript, applescript help, code, duplicates

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
AppleScripts work but flood Console with sandbox errors Aeryn Mac Programming 2 Nov 24, 2013 09:38 AM
EyeTV, HDHomerun Dual, and Recording OTA - Exporting, AppleScripts, etc. cpeek Apple TV and Home Theater 14 Apr 12, 2013 12:54 AM
AppleScripts snippets thread moonman239 Mac Programming 1 Jan 14, 2013 11:37 PM
Most consistent way of referring to iTunes playlists in Applescripts fhill2 Mac Programming 0 Jun 22, 2012 07:57 PM
iteration of a list in applescripts fhill2 Mac Programming 4 Jun 4, 2012 09:04 AM

Forum Jump

All times are GMT -5. The time now is 11:24 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC