【问题标题】:applescript times out when launching terminal启动终端时applescript超时
【发布时间】:2019-02-14 11:53:59
【问题描述】:

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

脚本如下

    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 上进行测试,它在那里运行良好。

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

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

提前致谢

【问题讨论】:

  • 有什么理由不能使用 AppleScript 中的 do shell script 命令而不是当前的 tell application "Terminal" ... end tell 块?例如,为什么不将所有代码替换为 do shell script "sudo &lt;path to my executable&gt;"
  • 试过但得到这个错误 sudo: no tty present and no askpass program specified

标签: terminal applescript appleevents


【解决方案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

【讨论】:

  • 运行了几次,有时没有。也许它只是 Mac OS 表现得很奇怪。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-16
  • 2014-09-10
  • 1970-01-01
  • 2022-12-18
  • 2020-09-08
相关资源
最近更新 更多