I have a small utility named Status Quo and I would like to command it via
AppleScript. Lot of tutorials around, but they’re for much more complicated
cases. Here’s the simplified one.
Goal is to implement following commands:
First thing to do is to prepare scripting definition (.sdef) file. It’s quite
easy if you’re aiming for commands only.
Following rules must be met to avoid The application has a corrupted dictionary error message:
suit code = 4 upper cased characters,
command code = 8 upper cased characters,
parameter code = 4 upper cased characters.
Lower case is reserved for Apple. Rest is pretty descriptive itself.
XML file saved as StatusQuo.sdef and added to the Status Quo Xcode project. Now we have to
add two properties into Info.plist file:
Scripting definition file name – StatusQuo.sdef,
Scriptable – YES.
Application is scriptable and the last thing to do is to implement ScriptSetAvailable, ScriptSetAway and ScriptSetDND classes by subclassing NSScriptCommand and overriding the performDefaultImplementation function.
NSScriptCommand supports both synchronous and asynchronous commands. Just
return value if your command is synchronous. Call suspendExecution(),
return nil and return your real value via resumeExecutionWithResult()
function if your command is asynchronous.
And … that’s it. We’re done. Lot of ways how to do it, but I personally
do like subclasses of NSScriptCommand. Here’re some links if you want to learn more: