Solved

Launch Application using AppleEvents

Posted on 1997-07-03
2
318 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 200 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 85
Installing Microsoft R server on REDHAT or SUSE Linux 4 136
Folder Comparison 12 54
Not needed 13 109
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now