我正在开发一个简单的小文本编辑器,它实现了 Apple Events ODBEditorSuite 的编辑器部分,以便我的应用程序可以与 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 事件正在发送,并且据我所知,directObject 描述符包含适当的数据。但是,在快速光标方面,我继续看到类似5/17/10 12:41:15 PM QuickCursor[177] Got ODB editor event for unknown file.
Console.app 中的消息。我已经从源代码构建了 QuickCursor,并且能够确定它没有从 directObject 描述符中获取正确的路径。
所以,我不知道在哪里可以超越这一点,因为这些NSAppleEventDescriptor
东西对我来说很陌生,而且有点老派的灰胡子骗术的味道:-P 但我希望有人听到会更好地精通这些咒语,也许能指出我什么我做错了。提前致谢。