views:

47

answers:

1

I'm working on a simple little text editor that implements the editor portion of the ODBEditorSuite of Apple Events so that my app can work with QuickCursor for providing editing capabilities. The events that need to be sent are pretty straightforward and share a lot of the same code, so I've wrapped it up into a method like this:

-(BOOL)postODBEditorAppleEvent:(OSType)type 
               withOldLocation:(NSString *)oldPath
                   newLocation:(NSString *)newPath
{
    NSData *targetBundleID = [@"com.hogbaysoftware.QuickCursor" dataUsingEncoding:NSUTF8StringEncoding];
    NSAppleEventDescriptor *targetDescriptor = [NSAppleEventDescriptor descriptorWithDescriptorType:typeApplicationBundleID data:targetBundleID];

    NSAppleEventDescriptor *appleEvent = [NSAppleEventDescriptor appleEventWithEventClass:kODBEditorSuite eventID:type targetDescriptor:targetDescriptor returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];

    NSAppleEventDescriptor *directObjectDescriptor = [NSAppleEventDescriptor descriptorWithDescriptorType:typeFSRef data:[oldPath dataUsingEncoding:NSUTF8StringEncoding]];
    [appleEvent setParamDescriptor:directObjectDescriptor forKeyword:keyDirectObject];

    if(newPath != nil){
        NSAppleEventDescriptor *newLocationDescriptor = [NSAppleEventDescriptor descriptorWithDescriptorType:typeFSRef data:[newPath dataUsingEncoding:NSUTF8StringEncoding]];
        [appleEvent setParamDescriptor:newLocationDescriptor forKeyword:keyNewLocation];
    }
    if(self.senderToken != nil){
        NSAppleEventDescriptor *tokenDescriptor = [NSAppleEventDescriptor descriptorWithDescriptorType:typeWildCard data:self.senderToken];
        [appleEvent setParamDescriptor:tokenDescriptor forKeyword:keySenderToken];
    }
    if (self.customPath != nil){
        NSData *customPathData = self.customPath;
        NSAppleEventDescriptor *customPathDescriptor = [NSAppleEventDescriptor descriptorWithDescriptorType:typeUnicodeText data:customPathData];
        [appleEvent setParamDescriptor:customPathDescriptor forKeyword:keyFileCustomPath];
    }   
    AEDesc reply = {typeNull, NULL};                                                        
    OSStatus status = noErr;
    status = AESend([appleEvent aeDesc], &reply, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
    return status == noErr;
}

By using NSLog() debugging, I've confirmed that the Apple Event is sending and as far as I can tell the directObject descriptor contains the appropriate data. But, on the Quick Cursor side, I continue to see messages like 5/17/10 12:41:15 PM QuickCursor[177] Got ODB editor event for unknown file. in Console.app. I've built QuickCursor from source and have been able to ascertain that it is not getting the proper path from the directObject descriptor.

So, I'm not sure where to go beyond this as the NSAppleEventDescriptor stuff is quite foreign to me and smacks of old school grey beard chicanery :-P but I was hoping someone hear would be better versed in such incantations and maybe point me to what I'm doing wrong. Thanks in advance.

A: 

I'm not sure why, but using [NSAppleEventDescriptor descriptorWithString:oldPath] worked fine. Using that now and have moved on to debugging other items. Maybe this helps someone else though.

jxpx777