【问题标题】:Applescript returns "<NSAppleEventDescriptor: " in Automator when it should be a stringApplescript 在 Automator 中返回“<NSAppleEventDescriptor:”,它应该是一个字符串
【发布时间】:2014-05-07 05:12:24
【问题描述】:

获取结果:

"<NSAppleEventDescriptor: [ 1 ]>"

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

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

为什么不只是打印字符串?我使用“设置为变量”将它设置为一个变量,然后我使用“获取变量”在我的 Python Shell 脚本之前获取该变量

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

var_1 = sys.argv[1]

【问题讨论】:

  • 您是否意识到您是在说您想要返回一个字符串但您正在返回一个数字?尝试在 "1" 和 "0" 周围加上引号,使它们成为字符串。

标签: string applescript automator dialog


【解决方案1】:

您如何尝试让它在 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

根据我对 Apple 的Creating Shell Script Actions 的阅读,为了通过 Automator 中的“运行 Shell 脚本”使用它,AppleScript 必须以字符串形式返回值。运行 Shell 脚本操作似乎没有执行 automatic type conversions

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

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

【讨论】:

  • 嘿,天龙座。我更新了使用 AppleScript 将值返回到 Automator 中的 Run Shell Script 的示例。令人惊讶的是(无论如何对我来说),尽管 Automator 具有执行类型转换的功能,但 Run Shell Script 并不麻烦,而且(如果我的阅读正确的话)要求所有输入都是字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 2016-01-14
  • 2017-02-14
  • 2013-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多