Applescript控制excel在优胜美地坏了?

Posted

技术标签:

【中文标题】Applescript控制excel在优胜美地坏了?【英文标题】:Applescript controlling excel broken in yosemite? 【发布时间】:2014-11-05 00:47:53 【问题描述】:

我有一个控制 Microsoft Excel 的小程序。我需要与系统事件交谈以单击一些对话框按钮。现在,在升级(原文如此)到 Yosemite 之后,脚本在两个错误之间交替出现(!!):

    “系统事件出错:连接无效。”数字 -609,光标在“打开 wbfile” '无法打开文档“tst”。系统事件无法打开“Microsoft Excel 97-2004 工作表格式”的文件。此错误在对话框中给出,之后单击“确定”可使脚本成功完成。

不知何故,在“告诉进程“Microsoft Excel”中打开工作簿不起作用。 我可以在“告诉应用程序“Microsoft Excel”中打开工作簿就好了,但是 我无法按下对话框按钮。

任何帮助表示赞赏!!!

set wbfile to "/private/tmp/tst.xls"
tell application "Microsoft Excel"
    activate
end tell
delay 0.1
tell application "System Events"
    delay 0.1
    tell process "Microsoft Excel"
        delay 0.1
        set foo to open wbfile
        try
            set cancel to button "Cancel" of window 1
            click (cancel)
        end try
        try
            set macros to button "Enable Macros" of window 1
            click macros
        end try
        try
            set links to button "Ignore Links" of window 1
            click links
        end try
    end tell
end tell

set dat to "flflfl"
set output to (dat as string)
return output

【问题讨论】:

【参考方案1】:

您可以使用ignoring application responses 并让 Excel 打开文件而无需等待应用程序的反馈。该脚本将立即进入下一步。 之后系统事件可以点击按钮:

set wbfile to "/private/tmp/tst.xls"
ignoring application responses
    tell application "Microsoft Excel"
        activate
        set foo to open wbfile
    end tell
end ignoring
delay 1
tell application "System Events"
    tell process "Microsoft Excel"
        try
            set cancel to button "Cancel" of window 1
            click (cancel)
        end try
        try
            set macros to button "Enable Macros" of window 1
            click macros
        end try
        try
            set links to button "Ignore Links" of window 1
            click links
        end try
    end tell
end tell

你好,迈克尔/汉堡

【讨论】:

太棒了!!我很高兴了解“忽略应用程序响应”。非常感谢!

以上是关于Applescript控制excel在优胜美地坏了?的主要内容,如果未能解决你的问题,请参考以下文章

使用扫描仪采集图像到优胜美地

优胜美地文件共享非活动帐户[关闭]

优胜美地和瓦尔格林德

如何在python中用opencv打开优胜美地序列

在优胜美地的 GCC 编译期间不再可能包含 Carbon 标头?

升级到优胜美地后无法在 tmux 中打开 sublime 文本