I'm trying to make a Swift app, 'Earwig.app', MacOS, scriptable. I've started by shamelessly stealing an example from Making Cocoa Application Scriptable Swift, adding two files, a .sdef and a .swift as listed below. I've set Scriptable and scripting definition filename in info.plist
My AppleScript is:
tell application "EarwigServer" to save in "path/to/file"
Running the script gives me an error, 'EarwigServer got an error: Can’t continue save.'
At this point I'm stuck. Any suggestions appreciated
sdef file:
<?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 file:
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: