0

I have a script wherein I need to run an executable from a terminal

the script is as below

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

but this times out with the error message

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

I even tried using a timeout like

with timeout of 5000 seconds

   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

but no luck it still times out...

This behaviour is observed sometimes , not always. I'm using El Capitan Mac OS.

I got a chance to test on Sierra and High Sierra and it works alright there.

Any idea, how can we solve this issue ?

Note: If I open a terminal before running this script, then it executes without any problems.

Thanks in advance

Abbas
  • 3,144
  • 2
  • 25
  • 45
  • Is there any reason why you can't utilize the [`do shell script`](https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW40) command from within your AppleScript instead of your current `tell application "Terminal" ... end tell` block? For instance, why not replace all your code with `do shell script "sudo "` – RobC Feb 15 '19 at 12:29
  • Tried it but got this error sudo: no tty present and no askpass program specified – Abbas Feb 19 '19 at 07:10

1 Answers1

1

How about trying something like this...

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
wch1zpink
  • 3,026
  • 1
  • 8
  • 19