【问题标题】:Automator AppleScript - trying to echo a string variable to BashAutomator AppleScript - 尝试将字符串变量回显到 Bash
【发布时间】:2020-11-15 21:25:55
【问题描述】:

我正在尝试使用 Automator 创建服务。

在运行 AppleScript 操作中,我有一个变量,它是一个字符串,其中每一行都是一个由换行符分隔的单词。像这样:

à
às
a
ante
ao
aos
após
aquela

当我尝试通过以下方式将其回显到终端时:

do shell script "echo " & (finalText as string)

我收到此错误:

The action “Run AppleScript” encountered an error: “sh: line 1: a: command not found
sh: line 2: à: command not found
sh: line 3: ante: command not found
...
sh: -c: line 30: syntax error near unexpected token `do'
sh: -c: line 30: `do'”

有什么想法吗?

【问题讨论】:

  • 当您说“尝试将字符串变量回显到 Bash”时,您到底想要做什么?我问是因为在 Run AppleScript action 中使用do shell script command 不会做很多事情,如果你所做的只是但是,从错误中回显一些文本字符串,您显然做的不止这些!无论如何,要摆脱 command not found 类型错误,请使用:do shell script "echo " & finalText's quoted form -- 至于 syntax error near unexpected token `do' 错误,没有看到所有代码,无法排除故障。
  • 太棒了。 's quoted form 成功了。请将此命令作为答案,以便我接受。

标签: applescript automator


【解决方案1】:

为了摆脱 command not found 在这种情况下的类型错误,并且几乎可以在将 variable 传递给 do shell script command 的任何时候em>,使用:

do shell script "echo " & finalText's quoted form

你也可以使用:

do shell script "echo " & quoted form of finalText

视情况而定。

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 2013-10-12
    • 2014-04-22
    • 2020-12-23
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多