
正在获取结果:
"<NSAppleEventDescriptor: [ 1 ]>"我在Automator中的Applescript外壳中有一个对话框
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脚本中,我简单地使用:
var_1 = sys.argv[1]发布于 2014-03-28 07:25:27
您如何尝试让它在Python中打印字符串?
此Python脚本根据对AppleScript的响应打印“1”或“0”:
#!/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之间的直接连接对此进行了测试。在每种情况下都适用相同的行为。
https://stackoverflow.com/questions/22701007
复制相似问题