[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Launch Application using AppleEvents

Posted on 1997-07-03
2
Medium Priority
?
358 Views
Last Modified: 2013-12-26
I used Apple's sample code to launch applications and it works with one problem. I used it to launch Simpletext but it does not create a new window for me.

Can someone please tell me how I can get it to work. :<
Please show source code for this :-)

Thanks for any help
MacDude
0
Comment
Question by:MacDude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:MacDude
ID: 1291525
Edited text of question
0
 
LVL 1

Accepted Solution

by:
Paul B earned 800 total points
ID: 1291526
If you want an application to open a specific document you should send it an open document AppleEvent.
If just want to launch an application with not document you should send an open application AppleEvent.
The open application AppleEvent tells the application to create a default window.
For TeachText, it should create an untitled window for you.

Here is code send an open application AppelEvent:

OSErr SendOpenApplicationToFile(FSSpec *docFSSpecPtr);
OSErr BuildOpenApplicationEvent(ProcessSerialNumber *targetPSN, AppleEvent *oappAppleEvent);
OSErr GetProcessFromFileSpec(const FSSpec * docFSSpecPtr, ProcessSerialNumber* currPSN);


OSErr SendOpenApplicationToFile(FSSpec *docFSSpecPtr)
{
      AppleEvent theAppleEvent, theReplyEvent;
      ProcessSerialNumber targetPSN;
      OSErr err;

      theAppleEvent.dataHandle = nil;

      err = GetProcessFromFileSpec(docFSSpecPtr, &targetPSN);
      if (!err) {
            err = BuildOpenApplicationEvent(&targetPSN, &theAppleEvent);
            if (!err)
                  err = AESend(&theAppleEvent,
                                          &theReplyEvent,
                                          kAENoReply,
                                          kAENormalPriority,
                                          kAEDefaultTimeout,
                                          nil,
                                          nil);
      }
      if (theAppleEvent.dataHandle != nil)  
            (void) AEDisposeDesc(&theAppleEvent);
      return err;
}

OSErr BuildOpenApplicationEvent(ProcessSerialNumber *targetPSN, AppleEvent *oappAppleEvent)
{
      OSErr                  err;
      AppleEvent            theAppleEvent;
      AEDesc                  targetAddrDesc;

      // to simplify cleanup, ensure that handles are nil to start
      targetAddrDesc.dataHandle      = nil;
      theAppleEvent.dataHandle      = nil;

      // create an address descriptor based on the serial number of
      // the target process
      err = AECreateDesc(typeProcessSerialNumber, (Ptr) targetPSN,
            sizeof(ProcessSerialNumber), &targetAddrDesc);
      if (err != noErr) goto Bail;

      
      // now make the 'oapp' AppleEvent descriptor
      err = AECreateAppleEvent(kCoreEventClass, kAEOpenApplication,
            &targetAddrDesc, kAutoGenerateReturnID, kAnyTransactionID,
            &theAppleEvent);
      if (err != noErr) goto Bail;
      
      *oappAppleEvent = theAppleEvent;

Bail:
      // dispose of everything that was allocated, except the return AE
      if (targetAddrDesc.dataHandle != nil)  (void) AEDisposeDesc(&targetAddrDesc);
      
      return err;

}

OSErr GetProcessFromFileSpec(const FSSpec * docFSSpecPtr, ProcessSerialNumber* currPSN)
{
      ProcessInfoRec currProcessInfo;
      FSSpec applicationSpec;
      short err;

      currPSN->lowLongOfPSN = kNoProcess;
      currPSN->highLongOfPSN = 0;

      currProcessInfo.processInfoLength = sizeof(ProcessInfoRec);
      currProcessInfo.processName = nil;
      currProcessInfo.processAppSpec = &applicationSpec;

      while (GetNextProcess(currPSN) == noErr) {
            if (GetProcessInformation(currPSN, &currProcessInfo) == noErr) {
                  if (
                        (applicationSpec.vRefNum == docFSSpecPtr->vRefNum) &&
                        (applicationSpec.parID == docFSSpecPtr->parID) &&
                        EqualString(applicationSpec.name, docFSSpecPtr->name, false, false)
                        ) {
                        return noErr;
                  }
            }
      }
      return fnfErr;
}

Good Luck,
Paul Baxter
pbaxter@assistivetech.com




0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question