Re: "Helper" applications
Re: "Helper" applications
- Subject: Re: "Helper" applications
- From: Gregory Weston <email@hidden>
- Date: Thu, 20 Dec 2007 15:53:29 -0500
Jacob Bandes-Storch wrote:
My preference pane contains in the Resources folder a "helper"
application. I've got a communication between them going with
distributed objects. The preference pane needs to be able to open and
close the helper (similar to the Growl and MySQL preference panes),
and see if it is currently running. I can use [[NSWorkspace
sharedWorkspace] launchedApplications] and see if any of those match
the file path of the helper app's bundle. I can launch the helper app
with [[NSWorkspace sharedWorkspace] openFile:]. I can monitor whether
or not it's open with notifications... Where I'm stuck is how to close
it. There doesn't seem to be a (recommended) way to access its
NSApplication instance to terminate it. How can I close the helper
app?
It's not a Cocoa solution, but I use this to see if a process is
running:
#include "ProcessIsRunningWithBundleID.h"
#include <IOKit/IOCFBundle.h>
int ProcessIsRunningWithBundleID(CFStringRef inBundleID,
ProcessSerialNumber* outPSN)
{
int theResult = 0;
ProcessSerialNumber thePSN = {0, kNoProcess};
OSErr theError = noErr;
do {
theError = GetNextProcess(&thePSN);
if(theError == noErr)
{
CFDictionaryRef theInfo = NULL;
theInfo = ProcessInformationCopyDictionary(&thePSN,
kProcessDictionaryIncludeAllInformationMask);
if(theInfo)
{
CFStringRef theBundleID = CFDictionaryGetValue(theInfo,
kIOBundleIdentifierKey);
if(theBundleID)
{
if(CFStringCompare(theBundleID, inBundleID, 0) ==
kCFCompareEqualTo)
{
theResult = 1;
}
}
CFRelease(theInfo);
}
}
} while((theError != procNotFound) && (theResult == 0));
if(theResult && outPSN)
{
*outPSN = thePSN;
}
return theResult;
}
And this to terminate a process:
OSErr QuitApplicationByPSN(const ProcessSerialNumber* inPSN)
{
AppleEvent theQuitEvent = {typeNull, NULL};
AEBuildError theBuildError;
OSErr theError = AEBuildAppleEvent(kCoreEventClass,
kAEQuitApplication,
typeProcessSerialNumber, inPSN,
sizeof(ProcessSerialNumber),
kAutoGenerateReturnID,
kAnyTransactionID,
&theQuitEvent,
&theBuildError,"");
if(theError == noErr)
{
AppleEvent theReply = {};
theError = AESend(&theQuitEvent, &theReply, kAENoReply |
kAENeverInteract,
kAENormalPriority, kNoTimeOut, NULL, NULL);
(void)AEDisposeDesc(&theQuitEvent);
}
return theError;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden