Hi folks,

Currently when working with NSAppleEventDescriptor it is necessary to drop down to legacy or deprecated Carbon APIs in order to perform certain tasks such as packing and unpacking date descriptors and sending Apple events. Given Apple's regular Carbon API pogroms, it's an uncomfortable foundation for building professional software products.

I'm putting together a Radar feature request requesting that NSAppleEventDescriptor be enhanced to provide this missing functionality, and writing the patch myself in the hope that a. this expedites the process, and b. it gets done right.

Here's what I've got so far, implemented as a category on NSAppleEventDescriptor so it's easy to test:


@interface NSAppleEventDescriptor (AEDescExtensions)

// Given a value, create and return an autoreleased NSAppleEventDescriptor
// that contains that value, with an appropriate type (typeLongDateTime,
// typeIEEE64BitFloatingPoint, or typeFileURL, respectively).

+ (instancetype)descriptorWithDate:(NSDate *)date;
+ (instancetype)descriptorWithDouble:(double)number;
+ (instancetype)descriptorWithFileURL:(NSURL *)fileURL;

// Given a target process identifier, create and return an autoreleased
// NSAppleEventDescriptor suitable for use in +appleEventWith... constructor

+ (instancetype)currentProcessDescriptor;
+ (instancetype)descriptorWithProcessID:(pid_t)pid;
+ (instancetype)descriptorWithApplicationURL:(NSURL *)url;

// AERecords can have an abitrary descriptorType. This allows you to check if
// the descriptor is truly an AERecord.

- (BOOL)isRecordDescriptor;

// Return the contents of a descriptor, after coercing the descriptor's contents // to typeLongDateTime, typeIEEE64BitFloatingPoint, or typeFileURL respectively.

@property (readonly) NSDate *dateValue;
@property (readonly) double doubleValue;
@property (readonly) NSURL *fileURLValue;

// Send an Apple event to a target process. On success, returns the reply event // containing the result value or error returned by the target process. If an // Apple Event Manager error occurs, returns nil and if `error` is not nil an
// NSError containing the Carbon error code.

- (instancetype)sendAppleEventWithMode:(AESendMode)sendMode
                               timeout:(long)timeOutInTicks
                                 error:(NSError * __autoreleasing *)error;

@end


These are the methods that wrap essential legacy/deprecated Carbon APIs:

      +descriptorWithDate:
      +currentProcessDescriptor
      -isRecordDescriptor
      -dateValue
      -sendAppleEventWithMode:timeout:error:

The rest are simply for completeness: not essential, just convenient to have.

The two source files that I'll submit as a code patch are here (you can ignore the larger project):

https://bitbucket.org/hhas/appleeventbridge/src/635415adc0841f07a906f834c7d269109db8ce3f/AppleEventBridge/NSAppleEventDescriptor+AEDescExtensions.h?at=master

https://bitbucket.org/hhas/appleeventbridge/src/635415adc0841f07a906f834c7d269109db8ce3f/AppleEventBridge/NSAppleEventDescriptor+AEDescExtensions.m?at=master


If anyone can think of any other Apple event Carbon APIs that should be added to this wrapper, please let me know. Ditto if you can see anything stupid or wrong in my implementation. I'm also open to advice on how to best present and document this code to make it as quick and painless for Apple to implement (I figure the less effort it is for them, the likelier they are to include it in [ideally] 10.11).

Thanks,

has

p.s. Anyone know if <rdar://problem/4976113> has been fixed? If it has, I can eliminate the AESendThreadSafe workaround for sending events on background threads.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to