Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applescript - Apple Event Timed out

I'm trying to open a very large excel file (*.xls) using applescript. The code is very simple, it looks like it is working, however after a few minutes I receive the following message:

Result: error "Microsoft Excel got an error: AppleEvent timed out." number -1712

Any idea about how to solve it? BTW using the automator doesn't work either.

Here's my code

    tell application "Microsoft Excel"
        activate
        open "/Users/sergioguerra1/Desktop/Detektor/Etapa II/Reporte General.xls"
        delay 300
    end tell
like image 469
user3416401 Avatar asked Mar 17 '14 03:03

user3416401


Video Answer


2 Answers

Try wrapping the open command in a with timeout block.

eg.

tell application "Microsoft Excel"
    activate
    with timeout of 3600 seconds
        open "/Users/sergioguerra1/Desktop/Detektor/Etapa II/Reporte General.xls"
    end timeout
end tell

This will override Applescripts default timeout of 2 mins, giving it longer to finish executing that command.

More info here in the AppleScript docs.

like image 70
adamh Avatar answered Oct 14 '22 19:10

adamh


Conversely, if you are wanting to open your excel file/s without having to wait 2 minutes or longer ( eg 3600 secs) for a timeout to occur, then you may prefer to delibertely trigger the timeout sooner, and catch the error with "try" block.
I've found this problem occurs when I use the "linked tables" feature in excel, and the linked table is no longer accessable. Excel pops up a nasty dialog 1/2 way through the "open" command and just hangs till you type ESC twice ( or similar ) eg:

        try
            with timeout of 10 seconds
                open some_excel_File
            end timeout
        on error -- excel timeout probably due to linked tables

            -- if the file has "linked tables" we need to hit esc twice after opening it. 
            tell application "System Events"
                repeat 2 times
                    key code 53
                    delay 3
                end repeat
            end tell

        end try
like image 20
Buzz Avatar answered Oct 14 '22 21:10

Buzz