Determine if an external app is running -or- a document for an external app is open

John Love <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
The challenge is how to determine if an external app is running *and*, if running, is a specific document for the external running app currently open.  The headache centers on the fact that everything works when the external document is closed, with its external app still running, that is, the external doc registers as not open.  BUT .. when the external app itself has quit, this external app does *not* register as not running.

BTW, I am using appscript which is an external 3rd party library I have brought in.  Even if someone is not familiar with appscript, I believe my problem is not related to appscript .. the reason I say this is because I have used non-appscript approaches with the same negative results.

Another BTW .. all this is taking place in a background Thread, that is, calls to -pingExtDoc are in the secondary Thread.

Reference -pingExtDoc below which 1st calls -pingExtApp .. if the external app has indeed quit, the instance parm = itsFileStatus should be set = kNoExtAppError by -pingExtApp.  In this case, -pingExtDoc simply bypasses all the doc-stuff, with the "damage" already registered via -pingExtApp's setting itsFileStatus = kNoExtAppError.  The background Thread tests itsFileStatus and terminates the background Thread because itsFileStatus is different from kNoError.  Then, we return to the main Thread.  Standard approach, I believe.

Here's where things get very spooky .. see "spooky" at the bottom of -pingExtDoc

=====

First, I determine if the external app itself is running via:

- (void )pingExtApp {
	
	extAppRunning = [itsExtApp isRunning];
	
	// -setFileStatus: calls NSMutableDictionary's setValue:theValueObject forKey:theKey
	extAppRunning ? [self setFileStatus:kNoError] : [self setFileStatus:kNoExtAppError];
	
}

Then, in my external doc method:

- (void )pingExtDoc {
	
	BOOL docActive = NO;

	[self pingExtApp];
	if ([self itsFileStatus] == kNoError) {
		itsExtDoc = [[itsExtApp windows] byName:itsFileName];   // autoreleased
		id appscriptResult = [[itsExtDoc exists] send];
		if (appscriptResult != nil)   docActive = [appscriptResult boolValue];
	}
 /*
	else  [self setFileStatus:kNoExtAppError];    // inside call to -pingExtApp
 */
	
	// Adding this "spooky" code eliminates the problem, other than the fact I'm calling -pingExtApp TWICE?

	if (!docActive) {
			
		// doc may not be active because the app has quit, so let's find out?
		[self pingExtApp];
		if ([self itsFileStatus] == kNoError)   [self setFileStatus:kNoExtDocError];
	     // else  [self setFileStatus:kNoExtAppError];    // from above call to -pingExtApp
	}
     // else docActive, in which case itsFileStatus = kNoError from above call to -pingExtApp

	// end "spooky"

}
=====

Thanks in advance

John Love
Touch the Future! Teach!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.