如何使我的PyObjC应用程序AppleScript能够

时间:2016-05-11 09:40:11

标签: python python-3.x applescript pyobjc

我想在OS X上使用Python创建一个应用程序,即AppleScript。

首先,我使用this tutorial创建了一个应用程序(它可以工作!)。然后我使用this SO answer添加AppleScript支持;我试图将Objective-C的东西翻译成Python。我在setup.py中添加了一个plist项:

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

我创建了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>

我添加了SimpleXibDemoIncreaseCommand类:

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

应用程序本身可行,但是当我运行AppleScript时:

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

我收到此错误:

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

我无法找到有关错误编号-1708的任何信息。当我用脚本编辑器打开应用程序时 - &gt;打开字典,没有任何反应。

这是什么问题?我有点卡住了: - /

0 个答案:

没有答案
相关问题