Wed. Morning Geek Out: Bring all items to your main monitor

I’m constantly connecting and disconnecting my laptop to and from my external monitors. The downside of this is that, with some regularity, when I unhook from my external monitors the items that were open on these monitors are not visible on my laptop screen (apparently the computer still thinks the externals are hooked up…OK Computer?). So, I can’t grab these items even though I can see them when I show all items using Expose. Even restarting the app doesn’t help.

Well, happily, there’s a script that remedies the problem. Cut and paste the script into Script Editor, and save it as whatever you want (I called the script “Center Items on Monitor”). I put it in my applications folder so that I can invoke it using Quicksilver.

Here’s the script:

— Example list of processes to ignore: {“xGestures”} or {“xGestures”, “OtherApp”, …}
property processesToIgnore : {}

— Get the size of the Display(s), only useful if there is one display
— otherwise it will grab the total size of both displays
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

One note, you need to check the box for “Enable Access for Assistive Devices” in the Universal Access preference pain.

Have at it.

[via Macosxhints]

Tags: , , ,


Your email address will not be published. Required fields are marked *