【问题标题】:How to call Automator variable in Applescript ?如何在 Applescript 中调用 Automator 变量?
【发布时间】:2014-02-18 22:37:22
【问题描述】:

所以我有一个 Applescript,它显示一个对话框,然后自动设置一个变量作为条目

例子。 . .输入“AAAAAAA” 查询变量将是“AAAAAAA”

我正在想办法在运行我的下一个 applescript 时调用该变量

我知道如何通过使用 sys.argv1 和 stdin -> 参数来使用 Python shell 脚本来做到这一点

如何使用 Applescript 实现这一目标?

我看到一个类似的帖子标题,但答案没有解决这个问题

【问题讨论】:

    标签: macos variables arguments applescript automator


    【解决方案1】:

    在运行 Applescript 操作中。

    你使用 return someVar 输出。

    ....
    
    return text_returned
        end run
    

    并且操作的输入通常在第一个参数中,名称为 input

    on run {input, parameters}
    ...
    

    on run {input, parameters}
    
        display dialog "test" default answer "" buttons {"Cancel", "OK"} default button 1
        copy the result as list to {button_pressed, text_returned}
    
        return text_returned
    end run
    

    on run {input, parameters}
    
        set theQuery to input
    end run
    

    如果你想重用它,你只需要在这种情况下设置变量。

    在此示例中,您可以将其删除,但仍会得到相同的结果。

    如果参数是一个列表,那么您将需要使用例如:

     on run {input, parameters}
    
            set theQuery to item 1 of input
        end run
    

    另请注意,如果您从 applescript 上下文/菜单脚本中获取显示对话框代码,它将为您提供以下行:copy the result as list to {button_pressed, text_returned}

    要在 Automator 中使用它,您需要将 :{button_pressed, text_returned} 换成 {text_returned, button_pressed}

    (去图..!)

    【讨论】:

    • 我认为set {button_pressed, text_returned} to {button returned, text returned} of resultcopy {button returned, text returned} of result to {button_pressed, text_returned}要好得多,因为这样你就不必依赖属性的顺序,这些属性实际上被指定为无序的。因此,显示的方法无处不在。
    猜你喜欢
    • 2013-04-13
    • 1970-01-01
    • 2013-10-12
    • 2023-03-18
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    相关资源
    最近更新 更多