0

我有一个脚本,我需要从终端运行可执行文件

脚本如下

    tell application "Terminal"
    activate
    set run_cmd to "sudo <path to my executable>"
    do script run_cmd
    end tell

但这超时并显示错误消息

error "Terminal got an error: AppleEvent timed out." number -1712

我什至尝试使用超时

超时时间为 5000 秒

   tell application "Terminal"
        activate
         with timeout of 5000 seconds
        set run_cmd to "sudo <path to my executable>"
        do script run_cmd
         end timeout
        end tell

但没有运气,它仍然超时......

有时会观察到这种行为,但并非总是如此。我正在使用 El Capitan Mac OS。

我有机会在 Sierra 和 High Sierra 上进行测试,它在那里运行良好。

任何想法,我们如何解决这个问题?

注意:如果我在运行这个脚本之前打开一个终端,那么它会毫无问题地执行。

提前致谢

4

1 回答 1

1

试试这样的东西怎么样...

tell application "Terminal" to launch
repeat while application "Terminal" is not running
    delay 0.2
end repeat
tell application "Terminal"
    activate
    set run_cmd to "sudo <path to my executable>"
    do script run_cmd
end tell
于 2019-02-14T17:27:56.580 回答