Applescript“无法让窗户小型化”

时间:2017-01-23 15:42:21

标签: applescript

我是一名初学者,正在研究一个在屏幕上的位置计算窗口的脚本。到目前为止,它运作得相当好,虽然有一个缺陷是计算最小化的窗口。

目前是以下工作代码:

tell application "System Events"
    set winCount1 to 0
    set winCount2 to 0
    set winCount3 to 0
    set winCount4 to 0
    set theProcesses to application processes
    repeat with theProcess from 1 to count theProcesses
        if visible of process theProcess is true then
            tell process theProcess
                repeat with x from 1 to (count windows)
                    if ((description of window x is not "dialog") then
                        set Pos to position of window x
                        if item 1 of Pos is less than -960 then
                            set winCount1 to winCount1 + 1
                        else if item 1 of Pos is less than 0 then
                            set winCount2 to winCount2 + 1
                        else if item 1 of Pos is less than 960 then
                            set winCount3 to winCount3 + 1
                        else
                            set winCount4 to winCount4 + 1
                        end if
                    end if
                end repeat
            end tell
        end if
    end repeat
    set countList to {winCount1, winCount2, winCount3, winCount4}
    return countList
end tell

现在尝试解决这个问题,我尝试添加一个新条件:

if ((description of window x) is not "dialog") and window x is not miniaturized then

但是这会返回标题中声明的错误。所以我试过了:

set props to get properties of window x
if props contains miniaturized then

这会返回相同的错误。

我也尝试过:

set props to get properties of class of window x
if props contains miniaturized then

同样的错误。

在测试之前没有微型化属性的窗口可能不难避免,但我没有找到解决方案的运气。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

获取窗口attribute "AXMinimized"的值,如下所示:

set winCount1 to 0
set winCount2 to 0
set winCount3 to 0
set winCount4 to 0
tell application "System Events"
    repeat with theProcess in (application processes whose visible is true)
        tell theProcess
            repeat with thisWin in windows
                if (description of thisWin is not "dialog") and not (value of attribute "AXMinimized" of thisWin) then
                    set Pos to position of thisWin
                    if item 1 of Pos is less than -960 then
                        set winCount1 to winCount1 + 1
                    else if item 1 of Pos is less than 0 then
                        set winCount2 to winCount2 + 1
                    else if item 1 of Pos is less than 960 then
                        set winCount3 to winCount3 + 1
                    else
                        set winCount4 to winCount4 + 1
                    end if
                end if
            end repeat
        end tell
    end repeat
end tell
return {winCount1, winCount2, winCount3, winCount4}