在 Objective C 中制作苹果脚本应用程序,出现奇怪的错误
好的,我已经有了一个应用程序,我想让它可以编写脚本。我设置了 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 消息。” number -1708 from 4
我还在我的 DocView 输出中得到:
返回脚本命令结果时出错:结果对象...是...无法转换为“布尔”类型的 Apple 事件描述符。类“NSCFString”的此实例不响应 -scriptingBooleanDescriptor 消息。
但是,如果我只返回直接布尔值,我会得到:
单步执行,直到退出函数 -[NSScriptingAppleEventHandler handleCommandEvent:withReplyEvent:], 其中没有行号信息。 程序收到信号:“EXC_BAD_ACCESS”。
所以,我想我有两个问题:1)为什么它认为它想要告诉 3 去一个页面? 2)从 applescript 返回布尔值的正确方法是什么?
谢谢。
Ok, so I've got an application, and I want to make it scriptable. I set up the plist, I set up the sdef file.
So far I have only one apple Event command: gotoPage. it takes an integer. and returns a boolean.
The relevant XML is:
<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>
I have an Objective-C class 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) is correct, and works fine.
When I call this, my program seems to work correctly. But then I get the error:
error "DocView got an error: 4 doesn’t understand the gotoPage message." number -1708 from 4
I also get, in my DocView output:
Error while returning the result of a script command: the result object... YES ...could not be converted to an Apple event descriptor of type 'boolean'. This instance of the class 'NSCFString' doesn't respond to -scriptingBooleanDescriptor messages.
However, if I return just the straight Boolean, I get:
Single stepping until exit from function -[NSScriptingAppleEventHandler handleCommandEvent:withReplyEvent:],
which has no line number information.
Program received signal: “EXC_BAD_ACCESS”.
so, I guess I've got 2 questions: 1) Why does it think it wants to tell 3 to goto a page? and 2) what is the correct way to return a Boolean from the applescript?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
返回[NSNumber numberWithBool:retval];
return [NSNumber numberWithBool:retval];