• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Who's launching me?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Who's launching me?


  • Subject: Re: Who's launching me?
  • From: Greg Robbins <email@hidden>
  • Date: Wed, 15 Feb 2006 09:20:31 -0800

>In thinking about this more, that's insufficient.  I really want
>to know which process called me telling me to open a document.


Handle the OpenDocuments event manually:

NSAppleEventManager *aeMgr = [NSAppleEventManager sharedAppleEventManager];

[aeMgr setEventHandler:myOpenDocumentsHandlerObject
   andSelector:@selector(myHandleOpenDocuments:withReplyEvent:)
   forEventClass:kCoreEventClass
   andEventID:kAEOpenDocuments]; // AppleEvents.h

then in the handler get the sender from the keyAddressAttr attribute of the Apple event:

- (void)myHandleOpenDocuments:(NSAppleEventDescriptor*)odocEvent
               withReplyEvent:(NSAppleEventDescriptor*)replyEvent {

  NSAppleEventDescriptor *theAEAddrDesc
    = [odocEvent attributeDescriptorForKeyword:keyAddressAttr];

  // the keyAddressAttr may be a ProcessSerialNumber or an OSType;
  // look for either

  NSData *thePSNData
    = [[theAEAddrDesc coerceToDescriptorType:typeProcessSerialNumber] data];

  if (thePSNData && ([thePSNData length] == sizeof(ProcessSerialNumber))) {

    ProcessSerialNumber thePSN
      = *(ProcessSerialNumber*) [thePSNData bytes];
    // use thePSN with Processes.h calls to get other info about the
    // sending app, including the signature
  }
  else {
    NSData *theOSTypeData
      = [[theAEAddrDesc coerceToDescriptorType:typeApplSignature] data];

    if (theOSTypeData && ([theOSTypeData length] == sizeof(OSType))) {

      OSType theSignature
        = *(OSType*) [theOSTypeData bytes];
      // this is the signature of the sending app; the PSN is
      // unspecified, though most likely Processes.h calls will only show
      // one running instance
    }
  }

  ...  // you should ignore the replyEvent parameter
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Who's launching me?
      • From: Camillo Lugaresi <email@hidden>
  • Prev by Date: "Path arithmetic" support in Quartz
  • Next by Date: Re: MDItemCreate very, very, very, slow -- and fails
  • Previous by thread: Re: Who's launching me?
  • Next by thread: Re: Who's launching me?
  • Index(es):
    • Date
    • Thread