我在Cocoa应用程序中添加了动词优先的AppleScript命令。sdef命令定义指示该命令返回文本字符串列表:
<command name="list names" code="ABCDLstN" description="return a list of names">
<cocoa class="ListNamesCommand"/>
<result type="text" list="yes" description="some names"/>
</command>ListNamesCommand类的performDefaultImplementation方法返回NSString的NSArray
- (id)performDefaultImplementation {
return @[@"name 1", @"name 2"];
}结果是一个例外:
2013-12-17 17:22:37.474 ListNames[31907:303] Error while returning the result of a script command: the result object...
(
name1,
name2
)
...could not be converted to an Apple event descriptor of type 'text'. This instance of the class '__NSArrayI' doesn't respond to -scriptingTextDescriptor messages.workaround是更改sdef以将结果类型指定为any而不是text,并返回NSAppleEventDescriptor而不是NSArray:
- (id)performDefaultImplementation {
NSAppleEventDescriptor *list = [NSAppleEventDescriptor listDescriptor];
[list insertDescriptor:[NSAppleEventDescriptor descriptorWithString:@"name 1"] atIndex:1];
[list insertDescriptor:[NSAppleEventDescriptor descriptorWithString:@"name 2"] atIndex:2];
return list;
}但是,这有一个不幸的副作用,即将事件(在AppleScript编辑器字典查看器中)记录为返回任何类型。
有没有没有这个缺点的解决方案?
发布于 2013-12-18 07:39:47
我认为当你定义命令时,类型应该是“文本列表”。我从来没看过关于"list=yes“的部分。我不是专家,但我会删除它。祝好运。
https://stackoverflow.com/questions/20646796
复制相似问题