Search code examples
macoscocoamacos-carbon

How to parse a Carbon AppleEvent using Cocoa (NSAppleEventDescriptor?)


In the process of modernizing a carbon app, I'd like to rewrite the handing of AppleEvents in Cocoa, especially because I find the Carbon AEFunctions quite ugly.

I found NSAppleEventDescriptor but I'm confused about how to create one from an AppleEvent* in order to easier access its elements.


Solution

  • An AppleEvent is an AERecord is an AEDescList is an AEDesc. So, you can create an NSAppleEventDescriptor using -initWithAEDescNoCopy:.

    That said, if you're writing Apple Event handlers in Cocoa, then you should register them with -[NSAppleEventManager setEventHandler:andSelector:forEventClass:andEventID:]. Your handler method would then receive an NSAppleEventDescriptor as a parameter and you wouldn't have to worry about constructing one from an AppleEvent.