脚本Cocoa应用程序

时间:2011-11-10 15:27:34

标签: cocoa applescript

我有一个测试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)?

1 个答案:

答案 0 :(得分:0)

查看Apple的SimpleScriptingVerbs示例代码。你的sayhello命令的sdef定义应该命名实现命令的NSScriptCommand的子类:

<command name="sayhello" code="sctshell" description="Says hello.">
    <cocoa class="SayHelloCommand"/>
</command>

然后将SayHelloCommand实现为NSScriptCommand的子类并覆盖其performDefaultImplementation方法。