【问题标题】:End of line error due to "use script"由于“使用脚本”导致的行尾错误
【发布时间】:2015-04-16 18:19:42
【问题描述】:

我有一个运行良好的苹果脚本,直到我在开头添加use script “Alert Utilities”。然后它给出预期的行尾等,但发现标识符。set md5 to do shell script "md5 -q " & quoted form of myFile 处的错误,shell 突出显示。什么可能导致此错误?

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    添加use scripting additions,代码将运行良好。自 AppleScript 2.3 (Mavericks) 以来,有新的 use 语句。它将告诉运行脚本所需的必要资源,例如 AppleScriptObjC 中的哪些应用程序(可选)、脚本库、可可框架,或者是否会使用脚本添加。为了在不使用 use 语句时向后兼容,默认情况下会加载脚本添加。如果使用use 语句,则默认不加载脚本添加。

    所以你的脚本看起来像:

    use script “Alert Utilities”
    use scripting additions
    -- continue code
    set md5 to do shell script "md5 -q " & quoted form of myFile
    

    【讨论】:

      【解决方案2】:

      添加use "scripting additions" 语句。 use 语句自动禁用脚本添加,例如 display dialog

      还有,

      set md5 to (do shell script "md5 -q " & quoted form of myFile with shell)
      

      【讨论】:

      • 我添加了use "scripting additions”,它给出了Expected AppleScript、script、application、framework or scripting added but found… 错误(不知道会有什么帮助) .我将他 do shell script 放在括号中,但这给出了 预期的“,”但找到了标识符。 错误。
      • 1) 不需要括号 2) 命令错误 3) 不要在use scripting additions 语句中使用引号(请参阅我的回答)。所以我什至很惊讶这个答案被投票赞成。
      • 我刚刚投了赞成票,因为我什至不知道use scripting additions,一旦我将它添加到我的脚本中,我的语法错误就消失了。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多