Reputation: 714
I'm a beginner working on a script that counts windows in locations on screen. So far it works fairly well, although one flaw is it counts windows that are minimized.
Here is the working code currently:
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
Now to try to solve this issue, I tried adding a new condition:
if ((description of window x) is not "dialog") and window x is not miniaturized then
But this returns the error stated in the title. So I tried:
set props to get properties of window x
if props contains miniaturized then
This returns the same error.
I also tried:
set props to get properties of class of window x
if props contains miniaturized then
Same error.
It can't be that difficult to avoid windows without the miniaturized property before testing for it, but I'm not having luck finding a solution. Any ideas?
Upvotes: 1
Views: 479
Reputation: 7191
Get the value of attribute "AXMinimized"
of the window, like this:
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}
Upvotes: 2