Move stray windows back into view in mac OS X

Today the iTunes Equilizer went walkabout on my mac. When I say it went walkabout I mean, I knew it was open because pressing F9 to show all windows proved it was open, but when I went to use it, it was somewhere up above the usable screen of my macbook. Well thanks to Dudehey and robg I found an answer.

I had already tried the more simple method of selecting the troublesome window using apple-~ and then choosing Window->Zoom. It failed to solve the issue.

The following steps will return all your open windows back to the useable and viewable part of the screen.

1) Open System Preferences -> Universal Access
2) Check the box ‘Enable access for assistive devices’ (remember to uncheck later if you need)
3) Close System Preferences
4) Run Applications -> AppleScript -> Script Editor
5) Paste the following code into the top box
6) Click Run
7) Quite Script Editor

-- start code
property processesToIgnore : {}
tell application "Finder"
	set _b to bounds of window of desktop
	set screen_width to item 3 of _b
	set screen_height to item 4 of _b
end tell
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
-- end code

And that’s it. I use Tiger 10.4 but apparently you can also use this method in Leopard 10.5.