2017-01-23 57 views
1

我是一名初學者,主要負責計算屏幕上位置窗口的腳本。到目前爲止它工作得很好,雖然有一個缺陷就是計算最小化的窗口。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 

同樣的錯誤。

在測試它之前,如果沒有小型化的屬性,就不可能很難避開窗戶,但我沒有找到解決方案的運氣。有任何想法嗎?

+0

我認爲這是一個錯誤。即使是「可微型化」的屬性也會引發錯誤。將它存檔到Apple。 – vadian

回答

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} 
+0

完美地工作。謝謝你也清理我的代碼。 –