使 Objective C 程序响应 applescript
我有一个 Objective C 程序,我正在尝试添加脚本能力。我已经阅读了文档,并且看到了 SimpleScripting 示例。所以,我有两个问题:
1)我是否正确地说每个(非标准)命令都需要它自己的类来响应该命令?该类可能只有一种方法。
2)让该类与程序的其余部分进行交流的公认方式是什么?例如,如果我希望命令告诉我的应用程序进行保存,脚本对象如何知道要向其发送消息的对象?我可以看到让我的 NSApplication 类设置一个全局 gApplication = this,然后通过它执行所有操作,但这似乎有点混乱......
I have an Objective C program, and I'm trying to add scriptability. I have read the docs, and I've seen the SimpleScripting examples. so, I have two questions:
1) Am I correct in saying that every (non-standard) command is going to need it's own class to respond to that command? And that class will probably only have one method.
2) What is the accepted way of having that class communicate with the rest of the program? if I want the command to tell my application to save, for example, how does the script object know about the object to send messages to? I can see making my NSApplication class set a global gApplication = this, and then do everything through that, but that seems kind of kludgy...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您可以定义 对象第一个脚本命令。在脚本字典中,使用类中的
元素来声明它接受命令以及要调用的方法。该方法必须采用NSScriptCommand*
。在某些标头中:
在脚本中调用时,会给出适当类型的对象作为第一个参数。
动词优先脚本命令 (需要子类化 NSScriptCommand)应该得到通过调用 NSScriptCommand 的
evaluatedArguments
方法。您需要处理的任何对象都应该可以从参数访问。如果不是,那么你的设计就有问题。No. You can define object first script commands. In the scripting dictionary, use the
<responds-to>
element in a class to declare that it accepts the command, and which method to call. The method must take anNSScriptCommand*
.In some header:
When called in a script, an object of the appropriate type is given as the first argument.
Verb-first script commands (which will require subclassing NSScriptCommand) should get passed the objects they need to work on by calling
NSScriptCommand
'sevaluatedArguments
method. Any objects you need to work on should be reachable from the arguments. If not, there's a problem with your design.