Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created December 28, 2014 11:46
Show Gist options
  • Save satoruhiga/6b8fcdd56081588f93b0 to your computer and use it in GitHub Desktop.
Save satoruhiga/6b8fcdd56081588f93b0 to your computer and use it in GitHub Desktop.
collect all windows
(*
collect all windows
http://apple.stackexchange.com/questions/709/how-to-retrieve-windows-that-have-moved-off-screen
http://d.hatena.ne.jp/hirose31/20111213/1323761962
*)
property processesToIgnore : {}
tell (do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution | tail -n 1") to set {screen_width, screen_height} to {word 2, word 4}
tell application "System Events"
set allProcesses to application processes
set _results to ""
repeat with i from 1 to count allProcesses
set doIt to 1
repeat with z from 1 to count processesToIgnore
if process i = process (item z of processesToIgnore) then
set doIt to 0
end if
end repeat
if doIt = 1 then
tell process i
repeat with x from 1 to (count windows)
set winPos to position of window x
set _x to item 1 of winPos
set _y to item 2 of winPos
if (_x < 0 or _y < 0 or _x > screen_width or _y > screen_height) then
set position of window x to {0, 22}
end if
end repeat
end tell
end if
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment