Я работаю над простым небольшим текстовым редактором, который реализует часть редактора ODBEditorSuite Apple Events, чтобы мое приложение могло работать с QuickCursor для обеспечения возможностей редактирования. События, которые нужно отправить, довольно просты и содержат много одинакового кода, поэтому я заключил их в метод, подобный следующему:
-(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;
}
Используя отладку NSLog()
, я подтвердил, что Apple Event отправляет, и, насколько я могу судить, дескриптор directObject содержит соответствующие данные. Но со стороны быстрого курсора я продолжаю видеть сообщения типа 5/17/10 12:41:15 PM QuickCursor[177] Got ODB editor event for unknown file.
в Console.app. Я построил QuickCursor из исходного кода и смог убедиться, что он не получает правильный путь из дескриптора directObject.
Итак, я не уверен, куда идти дальше, так как материал NSAppleEventDescriptor
совершенно чужд мне и попахивает старой школьной чучелой седой бороды :-P, но я надеялся, что кто-то услышит, что он лучше разбирается в таких заклинаниях и, возможно, укажет мне на то, что я делаю неправильно. Заранее спасибо.