1

我的 applescript 程序需要一些帮助。

我想列出所有打开的和在停靠栏中的窗口,所以我尝试了这个:

tell application "System Events"
set procs to processes
set windowInDock to {}
repeat with proc in procs
    try
        if exists (window 1 of proc) then
            repeat with w in (every window of proc whose miniaturized is true)
                copy a & w's miniaturized to the end of windowInDock
            end repeat
        end if
    end try -- ignore errors
end repeat
end tell
return windowInDock

但它返回空数组。

我尝试列出所有窗口并获取小型化参数(w 小型化),但它不起作用。

你有什么主意吗?

谢谢!

4

2 回答 2

3

exists命令适用于任何对象,但系统事件中的窗口属性与应用程序中的窗口属性不同(例如,没有小型化属性)。如果您不忽略所有错误,您会看到错误 - 在 try 语句中包装一堆代码而至少不记录错误只是要求它。

您可以做的是获取应用程序列表,然后要求他们获取有关其窗口的信息。不确定您要对真实值列表做什么,所以在我的示例中,我只使用了窗口索引:

tell application "System Events" to set theNames to name of processes whose background only is false
set windowsInDock to {}
repeat with appName in theNames
    tell application appName to repeat with aWindow in (get windows whose miniaturized is true)
        tell aWindow to try
            get it's properties -- see event log
            set the end of windowsInDock to "window " & it's index & " of application " & quoted form of appName
        on error errmess -- ignore errors
            log errmess
        end try
    end repeat
end repeat

choose from list windowsInDock with prompt "Miniaturized windows:" with empty selection allowed
于 2012-04-15T23:09:53.383 回答
2

这是一个适用于所有应用程序的脚本,至少在我的系统上。

尝试这个

set windowsInDock to {}
tell application "System Events"
    repeat with this_app in (get processes whose background only is false and windows is not {}) --get applications with 1+ window
        set windowsInDock to windowsInDock & (get windows of this_app whose value of its attribute "AXMinimized" is true)
    end repeat
end tell
return windowsInDock
于 2012-04-21T03:35:16.563 回答