在Objective C中制作一个可编写苹果脚本的应用程序,从而获得奇怪的错误

时间:2010-06-16 21:11:33

标签: objective-c applescript

好的,所以我有一个应用程序,我想让它可编写脚本。我设置了plist,我设置了sdef文件。

到目前为止,我只有一个苹果事件命令:gotoPage。它需要一个整数。并返回一个布尔值。

相关的XML是:

    <command name="gotoPage" code="dcvwgoto" description="Goto a specified page">
        <cocoa class="AEGoto"/>
        <direct-parameter description="Page Number" type="integer"/>
        <result description="True if the page exists, False othrewise" type="boolean"/>
    </command>

我有一个Objective-C类AEGoto.h:

@interface AEGoto :NSScriptCommand {
}
- (id)performDefaultImplementation;


- (id)performDefaultImplementation
{
    int page = [[self directParameter] intValue];
    Boolean retval = [gController setPage: page];
    return retval? @"YES" : @"NO";
}

setPage:(int)是正确的,并且工作正常。

当我这样称呼时,我的程序似乎正常工作。但后来我得到了错误:

错误“DocView出错:4不理解gotoPage消息。”数字-1708从4

我也在我的DocView输出中得到了:

返回脚本命令的结果时出错:结果对象... YES ...无法转换为类型为“boolean”的Apple事件描述符。类'NSCFString'的这个实例不响应-scriptingBooleanDescriptor消息。

但是,如果我只返回直布尔值,我得到:

单步执行直到退出函数 - [NSScriptingAppleEventHandler handleCommandEvent:withReplyEvent:], 没有行号信息。 程序接收信号:“EXC_BAD_ACCESS”。

所以,我想我有两个问题:1)为什么它认为它想告诉3去转页? 2)从applescript返回布尔值的正确方法是什么?

感谢。

1 个答案:

答案 0 :(得分:2)

return [NSNumber numberWithBool:retval];