• 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: Can I Send Apple Events in Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can I Send Apple Events in Cocoa?


  • Subject: Re: Can I Send Apple Events in Cocoa?
  • From: Matt Neuburg <email@hidden>
  • Date: Wed, 14 Dec 2005 13:40:19 -0800
  • Thread-topic: Can I Send Apple Events in Cocoa?

On Fri, 9 Dec 2005 21:07:40 -0800 (PST), Kaydell Leavitt
<email@hidden> said:
>Hi,
>
>I need to send an Apple Event to a program to automate
>exporting of data from it to a web-site.
>
>As far as I can tell, I can receive Apple Events in
>Cocoa, but I can't send them directly. (This was
>stated in "Cocoa Programming" in which they said that
>this was true as of 10.1.3)
>
>I understand that I could embed Apple Scripts in
>Cocoa, but this seems indirect and less good than just
>directly sending Apple Events and receiving a reply as
>to whether the export was successful or not.
>
>I believe that Apple is de-emphasizing Apple Events.
>I suppose the next generation software would use some
>kind of Unix technology for interapplication
>communication. I've heard a source at Apple say that
>this is faster.
>
>What I'm doing is fairly simple, I could embed an
>Apple Script in my Objective-C code. Or, I know Java,
>actually, I'd rather add to this Cocoa-Objective-C app
>that I've inerited and add the new functionality in
>Java. Or I understand that you can use the Cocoa
>framework and build on it with Apple Script Studio,
>which I guess is different than embedding Apple
>Scripts in Objective C.
>
>Can someone with experience give me a recommendation
>of how to proceed?

The upcoming second edition of my AppleScript book has a section on sending
Apple events without using AppleScript, and one of the methods I demonstrate
involves Cocoa. Here is some code:

ae =
[NSAppleEventDescriptor appleEventWithEventClass:'core'
eventID:'setd'
targetDescriptor:bbedit
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
[ae setParamDescriptor:
[NSAppleEventDescriptor descriptorWithString:@"Hello, world!"]
forKeyword:'data'];
AEDesc docu1;
CreateObjSpecifier('docu',
[[NSAppleEventDescriptor nullDescriptor] aeDesc],
formAbsolutePosition,
[[NSAppleEventDescriptor descriptorWithInt32:1]
aeDesc],
YES, &docu1);
AEDesc allText;
CreateObjSpecifier('ctxt', &docu1, formAbsolutePosition,
[[NSAppleEventDescriptor
descriptorWithDescriptorType:
'abso' bytes:"all " length:4] aeDesc],
YES, &allText);
NSAppleEventDescriptor* allTextDesc =
[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&allText];
[ae setParamDescriptor:allTextDesc forKeyword:keyDirectObject];
AESendMessage([ae aeDesc], NULL,
kAENoReply | kAENeverInteract,
kAEDefaultTimeout);

As you can see, I create the Apple event in Cocoa, but I create object
specifiers and actually send the Apple event using Carbon. Cocoa is
automatically linked to Carbon and Objective-C is C so this kind of hybrid
is easy. m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>



_______________________________________________
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

  • Prev by Date: RE: Options for graphic drawing?
  • Next by Date: Re: Options for graphic drawing?
  • Previous by thread: Re: Can I Send Apple Events in Cocoa?
  • Next by thread: NSObject Exercise comments?
  • Index(es):
    • Date
    • Thread