How to automagically move windows between monitors with one keystroke?

Posted on

QUESTION :

In Windows I had this great little app that allowed me to move application windows between 2 monitors with a click of a button (or a key-stroke).

I’m aware of an application that will change the position of a window WITHIN a monitor, but not BETWEEN monitors.

Do you know if there is in fact such an application?

ANSWER :

I use the following AppleScript to do what you’re asking to do; while it currently assumes the screens are the same size and positioned side-by-side, it should be relatively easy to change for other cases. Many techniques exist to run AppleScripts with keystroke commands; personally, I use Butler.

tell application "Finder"
    set _bounds to bounds of window of desktop
    set _width to item 3 of _bounds
end tell

set left_width to _width / 2

tell application "System Events"
    tell (first process whose frontmost is true)
        tell first window
            set {x, y} to (get position)
            if x < left_width then
                set position to {x + left_width, y}
            else
                set position to {x - left_width, y}
            end if
        end tell
    end tell
end tell

A quick search does yield a couple applications which include the functionality you’re looking for – none of which seem to be free, though. They do have trials. I’ll let you know if I find a free one.

SizeUp, Optimal Layout, WindowMover. SizeUp seems to be the best of the three, seeing as it’s made by the same makers as Cinch and seems most lightweight.

For Linux I am still looking for a solution.

UltraMon is a shareware that solves the problem nicely for Windows.

The following script can be used on Apple Mac OS X. The short cut can be created with Quicksilver

--  Window Moving Script between multiple monitors for Apple Mac OS X 10.x
-- (something I've been doing with UltraMon for quite a while)
-- inspired by:
-- http://www.tidbits.com/webx?14@@.3c7b1ae3/5
-- http://macscripter.net/viewtopic.php?id=24511
-- and http://daringfireball.net/2006/12/display_size_applescript_the_lazy_way
-- thanx for the input ... I was looking for a solution of this quite a while
-- best to be used with a custom trigger in Quicksilver where this script is assigned to a
-- keyboard short cut (I use ALT Cursor-Right)
-- you might want to put Quicksilver into your Autostart Objects
-- 2009-09-14 Wolfgang Fahl

--
-- get the front Window
--
on getFrontWindow1()
tell application "System Events"
set theFrontWindow to first window of (first process whose frontmost is true)
-- set theFrontWindow to the front window
set windowname to name of theFrontWindow as string
say "Moving" & windowname
--display dialog "front most windows is " & name of theFrontWindow buttons ("Cool") giving up after 3 default button 1
return theFrontWindow
end tell
end getFrontWindow1
--
-- get the front Window
--
on getFrontWindow()
tell application "System Events"
repeat with theapp in (every application process whose visible is true and frontmost is true)
repeat with ew in (every window of theapp)
return ew
end repeat
end repeat
end tell
end getFrontWindow
--
-- list all windows
--
on listWindows()
tell application "System Events"
repeat with theapp in (every application process whose visible is true and frontmost is true)
repeat with ew in (every window of theapp)
set windowname to name of ew as string
say windowname
end repeat
end repeat
end tell
end listWindows

--
-- message dialog
--
on show(aMessage)
-- display a dialog with a message
display dialog aMessage buttons {"Ok"} default button "Ok"
end show

--
-- get the screen information
--
on getScreenInfo(theIndex)
-- get the Screen Information from the windowserver defaults
-- we are using awk to go to the DisplaySets sections and assume that Active = ... is
-- at the start of each section
-- we'll find OriginX= ...,OriginY= ..., Width = ... and Height= ... entries
-- and return all of them a a list like
-- 0 0 1920 1200
-- 0 1920 1650 1050
set screenInfo to do shell script "defaults read /Library/Preferences/com.apple.windowserver | awk '
BEGIN { FS="="" }

Leave a Reply

Your email address will not be published.