我有一个测试AppleScript字典:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="ScriptTest Terminology">
<suite name="Standard Suite" code="????" description="Common classes and commands for all applications.">
<class name="application" code="capp" description="The application's top-level scripting object.">
<cocoa class="NSApplication"/>
</class>
</suite>
<suite name="MyApplication Suite" code="scts" description="MyApplication information.">
<class name="application" code="capp" description="The application's top-level scripting object." inherits="application">
<cocoa class="NSApplication"/>
<responds-to command="sayhello">
<cocoa method="sayHello:"/>
</responds-to>
</class>
<command name="sayhello" code="sctshell" description="Says hello.">
</command>
</suite>
</dictionary>
我的AppDelegate有方法:
- (void)sayHello:(NSScriptCommand*)scriptCommand;
但它从未被称为..为什么?
如何在appleScript中向我的应用程序类添加命令? (例如tell application
"Test" to sayhello
)?
答案 0 :(得分:0)
查看Apple的SimpleScriptingVerbs示例代码。你的sayhello命令的sdef定义应该命名实现命令的NSScriptCommand
的子类:
<command name="sayhello" code="sctshell" description="Says hello.">
<cocoa class="SayHelloCommand"/>
</command>
然后将SayHelloCommand
实现为NSScriptCommand
的子类并覆盖其performDefaultImplementation
方法。