AppleScript 无法通过终端获取参数值

AppleScript Can't Get Argument Value Through Terminal

我正在开发 Java 图形用户界面,我正在尝试制作一个可以使用给定的 phone 号码开始 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 并对其进行了修改,使其接收一个输入参数 phone 数字,而不是手动输入它进入脚本。我已经 运行 程序输入了一个实际的 phone 数字而不是输入变量并且它工作正常所以我知道问题在于传递参数。

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 上的任何地方都没有发现任何类似的东西。任何建议将不胜感激。

原因:

Error -1728在AppleScript中是"Can't get «script»",说明first item of args是脚本对象引用。这意味着命令行参数不会传递给您的 AppleScript 的 run 处理程序。

解决方案:

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

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