【问题标题】:Using an automator variable in Applescript在 Applescript 中使用自动机变量
【发布时间】:2021-07-16 01:16:23
【问题描述】:

我想在 Applescript(Automator 内部)中使用 Automator 变量,但我没有在网上找到有关如何操作的任何信息。 This is my Automator project,这是 Applescript:

tell application "Finder"
    delete file Path
    empty trash
end tell
end run

【问题讨论】:

    标签: variables applescript automator


    【解决方案1】:

    Automator 是可编写脚本的,因此在工作流程中您可以只使用它的术语,例如:

    set thePath to value of variable "Path" of front workflow
    tell application "Finder"
        delete file thePath
        empty trash
    end tell
    

    注意path是一个参数名,所以我在脚本中使用了不同的变量名。


    另一种选择是使用Get Value of Variable 并将其传递给Run AppleScript 操作,例如:

    • 要求文本

    • 设置变量值 {变量:测试}

    • -- 其他工作流程的东西--

    • 获取变量的值 {变量:测试}(忽略输入)

    • 运行 AppleScript

      on run {input, parameters} -- input is from the previous action
         set theValue to (first item of input) as number -- input is always a list
         if theValue > 1 then display dialog "It works!"
         -- return item(s) to the next action as needed
      end run
      

    【讨论】:

    • 如果我使用数字而不是路径,我将如何处理这个问题,因为 as number 不能使用自动机变量,至少对我来说是这样。
    • 它对我有用。变量的内容究竟是什么?
    • imgur.com/gallery/eXyz6Pk 我希望链接有效。
    • 我只是手动设置了用于测试的变量,但看起来文本操作中的富文本并没有被强制(Automator 就是这样愚蠢)。一种解决方法是在获取文本之后和Set Value of Variable 之前添加一个默认的Run Shell Script 操作(将输入作为参数传递)(我猜您链接中的Get 操作应该是Set) .另一种选择是 Get Value of Variable 并将其传递给 Run AppleScript 操作。我已经编辑了我的答案以添加它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2013-10-12
    • 2013-04-13
    • 1970-01-01
    • 2014-02-18
    • 2011-12-08
    相关资源
    最近更新 更多