Applescript:如何在所有空间中获取进程的窗口数?

时间:2012-04-26 09:41:09

标签: window applescript

将Microsoft Office更新到最新版本会导致每隔几个小时发生一次弹出错误。 “目前无法收到邮件。”只有重新启动应用程序才会使错误消失。许多人似乎没有解决这个问题,所以我(一个Windows程序员)决定编写我的第一个AppleScript。

首先,我尝试获取Office的窗口数:

tell application "Microsoft Outlook" to display dialog (count of windows)

返回1,这是不好的。这是否意味着弹出对话框不被OSX视为一个窗口?嗯。似乎不太可能。

第二,我试图从过程中获取窗口计数:

tell application "System Events" to tell process "Microsoft Outlook" to display dialog (count of windows)

返回2.很棒。窗口1是我需要的,我编写脚本,运行它,并且完美地工作......直到我从Outlook所在的空间变为另一个空间。从Windows的新空间计数返回0.在进一步的研究中,似乎空间模块不包含在Lion for AppleScript中。

任何人都知道如何在所有空间中计算进程窗口的数量?还有另一种检测弹出窗口的方法吗?

1 个答案:

答案 0 :(得分:0)

您可能需要激活该应用程序:

activate application "Microsoft Outlook"
tell application "System Events"
    tell process "Microsoft Outlook"
        if accessibility description of window 1 is "alert" then
            beep
            -- enter rest of your code
        end if
    end tell
end tell