1

I want to create an application on OS X with Python, that is AppleScript-able.

First I used this tutorial to create an Application (it works!). Then I used this SO answer to add AppleScript support; I tried to translate the Objective-C stuff into Python. I added a plist-item to the options in setup.py:

OPTIONS = {
    #...
    'plist': {
        'NSAppleScriptEnabled': True,
        'OSAScriptingDefinition': 'SimpleXibDemo.sdef',
    #...
    }
}

I created SimpleXibDemo.sdef

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="SimpleXibDemo">
    <suite name="SimpleXibDemo Suite" code="SXiD" description="SimpleXibDemo Scripts">
        <command name="increase" code="increxib" description="Increase the value">
            <cocoa class="SimpleXibDemoIncreaseCommand"/>
            <parameter name="by" type="integer" optional="yes">
                <cocoa key="by"/>
            </parameter>
            <result description="Returns the new value" type="integer"/>
        </command>
    </suite>
</dictionary>

and I added the class SimpleXibDemoIncreaseCommand:

class SimpleXibDemoIncreaseCommand(NSScriptCommand):
    def performDefaultImplementation(self):
        args = self.evaluatedArguments()
        nr = args.valueForKey("by")
        viewController.increment()
        return nr + 1

The application itself works, but when I run this AppleScript:

tell application "SimpleXibDemo"
    set myResult to increase by 3
end tell

I get this error:

error "SimpleXibDemo got an error: Can’t continue increase." number -1708

I can't find any info on error number -1708. And when I open the application with Script Editor -> Open Dictionary, nothing happens.

What is the problem here? I'm a bit stuck :-/

Community
  • 1
  • 1
doekman
  • 18,750
  • 20
  • 65
  • 86

0 Answers0