【问题标题】:How to use applescripts do shell script without quotes如何使用applescript做不带引号的shell脚本
【发布时间】:2019-04-07 19:41:19
【问题描述】:

我在 bash 中有一个程序可以更改我显示的 MAC 地址。我想用“do shell script”把这个程序变成一个applescript。但是,每当我在“do shell script”函数中运行代码时,它都不起作用。这很奇怪,因为它在终端中工作。

这是在我的 Mac 计算机上,我认为这是“执行 shell 脚本”功能后所需引号的问题。我尝试过更改报价顺序,但似乎不起作用。

sudo ifconfig en0 ether "$(openssl rand -hex 6 | sed 's/../&:/g;s/:$//')"

这是基本代码

do shell script "sudo ifconfig en0 ether "$(openssl rand -hex 6 | sed 's/../&:/g;s/:$//')"" with administrator privileges

这是此代码的 AppleScript 变体。

预计此代码会更改我的 MAC 地址,但它返回了“错误 -212”

【问题讨论】:

    标签: bash applescript sudo quotes


    【解决方案1】:

    不确定错误 -212 是什么,但在 AppleScript 中,(双)引号用于分隔字符串,因此要在 in 中使用它需要用反斜杠转义的字符串,例如例子

    do shell script "ifconfig en0 ether \"$(openssl rand -hex 6 | sed 's/../&:/g;s/:$//')\"" with administrator privileges
    

    请注意,sudo 不应与 administrator privileges 一起使用 - 请参阅 Apple 的 Technical Note TN2065

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多