首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Applescript在Automator中返回"<NSAppleEventDescriptor:“,而它应该是一个字符串

Applescript在Automator中返回"<NSAppleEventDescriptor:“,而它应该是一个字符串
EN

Stack Overflow用户
提问于 2014-03-28 07:00:16
回答 1查看 306关注 0票数 1

正在获取结果:

代码语言:javascript
复制
"<NSAppleEventDescriptor: [ 1 ]>"

我在Automator中的Applescript外壳中有一个对话框

代码语言:javascript
复制
display dialog "¿ What database did you use for your sequences ?" buttons {"RefSeq", "Ensembl"} default button 2
set the button_pressed to the button returned of the result
if the button_pressed is "RefSeq" then
    return 0
else if the button_pressed is "Ensembl" then
    return 1
end if

为什么不直接打印字符串呢?我使用"Set to Variable“将其设置为一个变量,然后使用"Get the Variable”在Python Shell脚本之前获取该变量

在Python Shell脚本中,我简单地使用:

代码语言:javascript
复制
var_1 = sys.argv[1]
EN

回答 1

Stack Overflow用户

发布于 2014-03-28 07:25:27

您如何尝试让它在Python中打印字符串?

此Python脚本根据对AppleScript的响应打印“1”或“0”:

代码语言:javascript
复制
#!/usr/bin/python
# -*- coding: utf-8 -*-

from subprocess import Popen, PIPE

script = '''
display dialog "¿ What database did you use for your sequences ?" buttons {"RefSeq", "Ensembl"} default button 2
set the button_pressed to the button returned of the result
if the button_pressed is "RefSeq" then
    return 0
else if the button_pressed is "Ensembl" then
    return 1
end if
'''

macosx = Popen('/usr/bin/osascript', stdin=PIPE, stdout=PIPE, stderr=PIPE)
(response, error) = macosx.communicate(script)
response = response.strip()

print response

根据我对苹果Creating Shell Script Actions的理解,为了在Automator中通过“Run Shell Script”使用它,AppleScript必须以字符串的形式返回值。运行外壳脚本操作似乎不执行automatic type conversions

在示例脚本中,您可以通过将“return 0”和“return 1”更改为“return”0“”和“return”1“来修复此问题:

我使用变量操作的Set/Get值以及Run AppleScript和Run Shell Script之间的直接连接对此进行了测试。在每种情况下都适用相同的行为。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22701007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档