【问题标题】:AppleScript Can't Get Argument Value Through TerminalAppleScript 无法通过终端获取参数值
【发布时间】:2019-03-14 19:12:33
【问题描述】:

我正在开发 Java GUI,我正在尝试制作一个可以使用给定电话号码启动 FaceTime 通话的按钮。这是java代码的一个过度简化的版本。

String cellNum = "18001234567";
try {
    Runtime.getRuntime().exec("open /Users/faris/Desktop/call.app --args " + cellNum);
} catch (IOException e) {
    e.printStackTrace();
}

在研究了如何做到这一点后,我复制了我在网上找到的 AppleScript 应用程序的一部分,我将其命名为 call.app 并对其进行了修改,使其接受输入参数电话号码,而不是手动将其输入到脚本中。我已经用输入的实际电话号码而不是输入变量来运行程序,它工作正常,所以我知道问题在于传递参数。

call.app

on run args
    set input to first item of args
    open location "tel://" & input & "?audio=yes"
    delay 1
    tell application "System Events"
        key code 36
    end tell
end run

这是我每次从 AppleScript 中得到的错误。

Can’t get item 1. (-1728)

我以前从未使用过 AppleScript,所以我现在完全迷路了。在 SO 上的任何地方都没有发现任何类似的东西。任何建议将不胜感激。

【问题讨论】:

    标签: java macos terminal arguments applescript


    【解决方案1】:

    原因:

    AppleScript 中的Error -1728"Can't get «script»",表示first item of args 是一个脚本对象引用。这意味着命令行参数没有传递给 AppleScript 的 run 处理程序。

    解决办法:

    不要将 AppleScript 保存为小程序,而是将其保存(导出)为 .scpt.applescript 文件。然后用你的exec(...) Java 命令替换这个:

    exec("osascript /path/to/applescript " + cellNum);
    

    【讨论】:

      猜你喜欢
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 2016-04-08
      • 2021-10-13
      • 1970-01-01
      相关资源
      最近更新 更多