我正在研究一个简单的小文本编辑器,它实现了Apple事件的ODBEditorSuite的编辑器部分,以便我的应用程序可以使用QuickCursor提供编辑功能。需要发送的事件是非常简单和共享很多相同的代码,所以我把它包成这样的方法:请帮助ODBEditorSuite Apple Event voodoo?
-(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描述符包含适当的数据。但是,在快速光标方面,我继续在Console.app中看到类似5/17/10 12:41:15 PM QuickCursor[177] Got ODB editor event for unknown file.
的消息。我从源代码构建了QuickCursor,并且已经能够确定它没有从directObject描述符获得正确的路径。
所以,我不知道哪里去超越这个作为NSAppleEventDescriptor
东西是很陌生的我和老同学灰胡子欺骗之嫌,但:-P我希望有人听到会在这样的咒语来更好地熟悉和也许指出我做错了什么。提前致谢。