"Helper" applications

  • 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?
  • On Dec 20, 2007, at 9:06 AM, 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.

    [...]

    > How can I close the helper app?

    You have an object that your helper app "publishes" via Distributed
    Objects (DO), right? Add a method to that object that calls [NSApp
    terminate:], and call that method over DO when you want your helper
    to quit.

    _murat
  • 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;
    }
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today