[英]Why isn't making my Swift app scriptable working?
我正在尝试制作 Swift 应用程序,“Earwig.app”,MacOS,可编写脚本。 我开始无耻地从Making Cocoa Application Scriptable Swift中窃取示例,添加两个文件 a.sdef 和 a.swift 如下所列。 我在 info.plist 中设置了 Scriptable 和脚本定义文件名
我的 AppleScript 是:
tell application "EarwigServer" to save in "path/to/file"
运行脚本给我一个错误,“EarwigServer 出现错误:无法继续保存。”
在这一点上,我被困住了。 任何建议表示赞赏
sdef 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="ScriptableSwift Terminology">
<suite name="ScriptableSwift Scripting Suite" code="SSss" description="Standard suite for application communication.">
<command name="save" code="SSssSave" description="Save something.">
<cocoa class="ScriptableSwift.SaveScriptCommand"/>
<parameter name="in" code="Fpat" type="text" description="The file path in which to save the document.">
<cocoa key="FilePath"/>
</parameter>
<result type="text" description="Echoes back the filepath supplied."/>
</command>
</suite>
</dictionary>
swift 文件:
import Foundation
import Cocoa
class SaveScriptCommand: NSScriptCommand {
override func performDefaultImplementation() -> Any? {
print( "in" )
let filePath = self.evaluatedArguments!["FilePath"] as! String
print( "here" )
return filePath
}
}
信息列表:
当我将ScriptableSwift.SaveScriptCommand
更改为EarwigServer.SaveScriptCommand
时,它开始工作。 这似乎很明显,我知道,但我以前做过,但没有任何效果。 在我清理构建文件夹之前,更改似乎不会生效。
这个 xml 有效,swift 文件保持不变:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="EarwigServer Terminology">
<suite name="EarwigServer Scripting Suite" code="ESss" description="Standard suite for application communication.">
<command name="run" code="ESssErun" description="Save something.">
<cocoa class="EarwigServer.SaveScriptCommand"/>
<parameter name="in" code="Fpat" type="text" description="The file path in which to save the document.">
<cocoa key="FilePath"/>
</parameter>
<result type="text" description="Echoes back the filepath supplied."/>
</command>
</suite>
</dictionary>
感谢您的输入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.