【问题标题】:How to pass variable from AppleScript to Automator?如何将变量从 AppleScript 传递给 Automator?
【发布时间】:2020-12-23 05:31:34
【问题描述】:

我正在寻求有关将变量从 AppleScript 传递到 Automator 的帮助。

我正在开发一个小型自动化应用程序。我需要键入一个将添加到 PDF 名称末尾的数字。我在automator中使用了“询问文本”,但是,我发现,首先,弹出窗口不会停留在屏幕的中心。 (27" iMac.),第二,每次输入数字后,我需要用鼠标点击确定,回车键不起作用。

所以我求助于 AppleScript。这是我找到的,一个让我输入数字的窗口,然后单击继续,然后将数字传递给 Automator 以添加到 PDF 的名称中。

  1. 将变量的值设置为存储
  2. 运行 AppleScript:忽略此操作的输入。
on run {input, parameters}

  display dialog "Please enter QC Round." default answer "" with icon stop buttons {"Cancel", "Continue"} default button "Continue"
--> Result: {button returned:"Continue", text returned:"MySecretPassphrase"}

  return input
end run
  1. 将变量的值设置为继续
  2. 获取变量值存储
  3. 重命名查找器项目:添加文本 名称后加:_QC_Continue(Variable)

但它不起作用。谁能帮我修一下?

【问题讨论】:

    标签: macos applescript automator


    【解决方案1】:

    在 Automator 中,动作从前一个动作获取输入,并将其结果传递给下一个动作。在 Run AppleScript 操作中,输入位于 run 处理程序的 input 参数中,处理程序返回的项目是传递的内容。

    在您的示例中,您只是传递了input,它没有值,因为操作忽略了它的输入。解决方法是从对话框中返回文本,例如:

    on run {input, parameters}
       set dialogResult to (display dialog "Please enter QC Round." default answer "" with icon stop buttons {"Cancel", "Continue"} default button "Continue")
       return text returned of dialogResult
    end run
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-09
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多