0

我在 py2app 捆绑的 Python 2.7 应用程序中使用 appscript 和 aemreceive 来接受传入的 Apple 事件并将我的应用程序的输出作为 Apple 事件返回给与我的应用程序通信的外部应用程序。

这很好用,有一个例外:当我返回字典时,键被管道字符包围,我需要没有这些字符的键。

示例:我想将此响应发送到外部应用程序:

{has description:true, folder:file "travellerHD:Users:andre:Desktop:MyNewFile"}

相反,我的应用程序发送了这个:

{|has description|:true, |folder|:file "travellerHD:Users:andre:Desktop:MyNewFile"}

事件处理程序已使用以下代码安装:

aemreceive.installeventhandler(get_property, "coregetd",
                               ('----', 'request_string',
                                aemreceive.kae.typeAERecord),
                              )

其中“get_property”是一个函数的名称,一旦外部应用程序请求项目的位置信息,就会调用该函数。这个函数返回一个字典:

return {'has description': asset.has_description,
        'folder': mactypes.File(asset.folder)}

我了解到,如果您想使用 Apple Events 保留字(如“文件夹”)作为应用程序的键,或者您的键使用空格或非 ASCII 字符,则必须使用管道围绕键。因此,当我从“有描述”中删除空格或将“文件夹”键重命名为“myfolder”时,我的应用程序返回一个字典,而不用管道包围键。

然而,与我的应用程序通信的外部应用程序要求我的应用程序使用带有空格的键以及“文件夹”键。

有任何想法吗?

提前非常感谢。

4

1 回答 1

0

弄清楚它是如何工作的。

在我的 sdef 文件中定义了属性:

<property name="has description" code="ashd" type="boolean" description="Whether the library has an XML description.">
</property>
<property name="folder" code="asfd" type="file" description="Directory in which the library files exist.">
</property>

而不是像这样将键作为字符串返回:

return {'has description': asset.has_description,
        'folder': mactypes.File(asset.folder)}

我现在只需返回四个字符代码并让 aem 完成繁重的工作:

return {aem.AEType('ashd'): asset.has_description,
        aem.AEType('asfd'): mactypes.File(asset.folder)}
于 2016-07-11T14:19:05.357 回答