【问题标题】:Multiple Applescript lines from terminal osascript call来自终端 osascript 调用的多个 Applescript 行
【发布时间】:2021-09-20 04:24:16
【问题描述】:

所以我试图从命令行一次性运行多个 Applescript 命令。但是,无论我如何尝试,它都不起作用:

$ osascript -e "set x to 0; display dialog x"
$ osascript -e "set x to 0 \n display dialog x"
$ osascript -e "set x to 0 then display dialog x"

有没有办法在不保存到文件的情况下做到这一点?

【问题讨论】:

    标签: applescript osascript


    【解决方案1】:

    这对我有用:

    osascript -e "set x to 0" -e "display dialog x"
    

    查看手册页中的-e 选项,用于终端中的osascriptman osascript

    -e 声明
    输入一行脚本。如果给出 -eosascript 将不会在参数列表中查找文件名。可以给出多个 -e 选项来构建多行脚本。因为大多数脚本使用许多 shell 程序特有的字符(例如,AppleScript 使用单引号和双引号、“(”、“)”和“*”),因此必须正确引用和转义语句让它完好无损地通过外壳。

    你也可以这样做:

    osascript <<END         
    set x to 0       
    display dialog x
    END
    

    或者:

    osascript -e '          
    set x to 0
    display dialog x'
    

    【讨论】:

      【解决方案2】:

      您的第二次尝试非常接近正确:

      osascript -e "set x to 0 
      PRESS ENTER
      display dialog x"
      PRESS ENTER
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-13
        • 2017-08-26
        • 1970-01-01
        • 2013-05-03
        相关资源
        最近更新 更多