Solved

Launch Application using AppleEvents

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 91
Doc'in system (example?) BA 7 120
only14 challenge 19 84
firstChar challenge 13 133
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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