【问题标题】:Applescript Passing a Variable Into Shell CommandApplescript 将变量传递给 Shell 命令
【发布时间】:2016-01-05 06:48:37
【问题描述】:

我正在尝试编写脚本来安装驱动器。因为这是我经常做的事情。但是,我不熟悉 Applescript。到目前为止,我还没有找到如何将查询传递给命令?

如果你不介意给我看,那就太棒了!一点解释也很好,因为我确实想了解它的作用。

(choose from list {"disk0s2", "disk2s1", "disk2s2", "disk3s1", "disk3s2", "disk4s1", "disk4s2"} with prompt "What disk are you trying to mount?")
set disk to result as text

repeat 5 times
do shell script "diskutil mount readOnly /dev/disk3s1" with administrator privileges
end repeat

【问题讨论】:

    标签: applescript


    【解决方案1】:

    你必须用你的变量替换 do shell script 命令的一部分,并用 & 连接所有命令:

     do shell script "diskutil mount readOnly /dev/" & disk" with administrator privileges
    

    【讨论】:

    • 我只好把disk后面的引号去掉了,谢谢!
    【解决方案2】:

    您需要使用 Applescript 吗?这对于 bash 来说是微不足道的。如果为每个磁盘制作一个脚本,如下所示:

    #!/bin/sh
    
    diskutil mount readOnly /dev/disk2s1
    

    您可以通过右键单击打开方式,然后单击其他...并选择终端,使脚本可双击。 (您在浏览终端应用程序时可能需要选择所有应用程序)。

    【讨论】:

    • 我曾想过,但这使它成为一个脚本,而不是多个文件。
    猜你喜欢
    • 1970-01-01
    • 2015-01-08
    • 2012-04-24
    • 1970-01-01
    • 2022-12-13
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多