applescript times out when launching terminal

481 Views Asked by At

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

1

There are 1 best solutions below

1
wch1zpink On

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