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:

It started working when I changed ScriptableSwift.SaveScriptCommand to EarwigServer.SaveScriptCommand. Which seems obvious, I know but I'd done this before with no effect. It seems that changes don't take effect until I cleaned the build folder.
This xml works, the swift file remains unchanged:
<?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>
Thanks for the input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With