[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Launch Application using AppleEvents

Posted on 1997-07-03
2
Medium Priority
?
370 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

872 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