【发布时间】:2019-11-21 10:13:37
【问题描述】:
我正在尝试制作一个 Swift 应用程序,“Earwig.app”,MacOS,可编写脚本。我首先从Making Cocoa Application Scriptable Swift 无耻地窃取了一个示例,添加了两个文件,一个.sdef 和一个.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>
快速文件:
import Foundation
import Cocoa
class SaveScriptCommand: NSScriptCommand {
override func performDefaultImplementation() -> Any? {
print( "in" )
let filePath = self.evaluatedArguments!["FilePath"] as! String
print( "here" )
return filePath
}
}
info.plist:
【问题讨论】:
-
它不能工作的原因有很多。麻烦的是任何微小的错误都会破坏整个功能。例如,您是否在 Info.plist 中添加了所需的键和值?
-
我很确定我的 info.plist 是正确的,但我已经编辑了帖子并添加了屏幕截图。我几乎只是从一个示例项目中添加了这两个文件,以便根据需要调整它们。我想知道我的类名 ScriptableSwift.SaveScriptCommand 是不是弄错了。我尝试了许多排列都没有运气。
标签: swift macos scriptable