Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Dec 22, 2010, 05:48 AM   #1
the Otter
macrumors newbie
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:
tell application "System Events" to set previousScript to (name of processes) contains "the 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?

“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'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

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

applescript, applescript help, code, duplicates

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Sync Creates duplicates (or more) in Contacts Bucharoo1 iCloud and Apple Services 5 Jul 9, 2011 11:12 PM
Applescript with cocoa Renmusxd Mac Programming 0 Nov 16, 2010 11:06 PM
AppleScript Application fivetoadsloth OS X 0 Nov 15, 2010 06:35 PM
Handling duplicate entry errors? MythicFrost Web Design and Development 5 Apr 7, 2010 11:05 AM
Handling Duplicates jayb2000 Digital Photography 0 Jan 24, 2007 07:16 PM

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

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

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