Applescript - Apple Event Time out out

时间:2014-03-17 03:08:29

标签: excel applescript

我试图使用applescript打开一个非常大的ex​​cel文件(* .xls)。代码非常简单,看起来它正在工作,但几分钟后我收到以下消息:

结果: 错误" Microsoft Excel出错:AppleEvent超时。"编号-1712

有关如何解决它的任何想法?使用自动机的BTW也不起作用。

这是我的代码

    tell application "Microsoft Excel"
        activate
        open "/Users/sergioguerra1/Desktop/Detektor/Etapa II/Reporte General.xls"
        delay 300
    end tell

2 个答案:

答案 0 :(得分:3)

尝试在with timeout块中包装open命令。

例如

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

这将覆盖Applescripts默认超时2分钟,使其完成执行该命令的时间更长。

更多信息here in the AppleScript docs

答案 1 :(得分:1)

相反,如果您想要打开excel文件而无需等待2分钟或更长时间(例如3600秒)才能发生超时,那么您可能希望尽快故意触发超时 ,并使用"尝试"块。
我发现当我使用"链接表时出现这个问题" excel中的功能,并且链接表不再可访问。 Excel通过"打开"以1/2的方式弹出一个讨厌的对话框。命令并挂起,直到你键入ESC两次(或类似),例如:

        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