请帮助 ODBEditorSuite Apple Event voodoo 吗?
我正在开发一个简单的小型文本编辑器,它实现了 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 描述符包含适当的数据。但是,在快速光标方面,我继续在 Console.app 中看到类似 5/17/10 12:41:15 PM QuickCursor[177] Got ODB editor event forknown file.
的消息。我已经从源代码构建了 QuickCursor,并且能够确定它没有从 directObject 描述符获取正确的路径。
所以,我不知道除此之外该去哪里,因为 NSAppleEventDescriptor
的东西对我来说很陌生,而且有点老派灰胡子诡计的味道 :-P 但我希望有人听到会更精通这样的咒语也许会让我意识到我做错了什么。提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么,但使用
[NSAppleEventDescriptor DescriptorWithString:oldPath]
效果很好。现在使用它并继续调试其他项目。也许这对其他人有帮助。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.