gpt4 book ai didi

cocoa - 编写 Cocoa 应用程序脚本

转载 作者:行者123 更新时间:2023-12-03 17:25:10 24 4
gpt4 key购买 nike

我有一个测试 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 中向我的应用程序类添加命令? (例如告诉应用程序
“测试”打招呼
)?

最佳答案

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

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

然后将 SayHelloCommand 实现为 NSScriptCommand 的子类,并重写其 performDefaultImplementation 方法。

关于cocoa - 编写 Cocoa 应用程序脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8081936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com