#cocoa #applescript
#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:
Взгляните на образец кода Apple SimpleScriptingVerbs. Ваше sdef-определение команды sayhello должно называть подкласс NSScriptCommand
, который реализует команду:
<command name="sayhello" code="sctshell" description="Says hello.">
<cocoa class="SayHelloCommand"/>
</command>
Затем реализуйте SayHelloCommand
как подкласс NSScriptCommand
и переопределите его performDefaultImplementation
метод.