Move all windows to a single monitor (with two attached) in Mac OS X? [closed]
Asked Answered
L

6

28

Whenever I use my MacBook away from my desk and later plug it into an external display (as primary), I get into the state of having windows deposited in both the notebook monitor and the external one.

To move all windows to a single screen, my current solution is to "Turn on mirroring" in the display preferences and then turn it off again. This is rather tedious, though. Does anyone know of a better way?


I'm afraid the script posted by @erlando does absolutely nothing for me, running Mac OS X 10.5.4. (I.e., with windows on both screens, running the script moves not a single one of them, and it does not return any errors.) I guess I'll just have to stick with using the "mirror/unmirror" method mentioned above.


@Denton: I'm afraid those links provide scripts for getting windows which are orphaned from any screen back onto the display. I ‘just’ want to move all windows from a secondary display onto the primary display.

Laing answered 2/9, 2008 at 9:5 Comment(5)
Shouldn't this question be moved to a user-focused SE site by now? SO is for programming questions, and this isn't one.Calvities
Funny to look back at the old questions when you couldn't even comment so had to append them to the question itself :)Laing
Turning on and off mirroring does nothing for me on 10.15.5Postilion
This way is rather hacky and uses paid 3rd party software (partially why I'm posting as a comment), but if one were to use BetterTouchTool there is an action called "Move & maximize all windows to mouse display" which does exactly as it says! Also one thing to note is that this won't work for full-screened apps.Bitten
After some testing and going back and forth with other apps/workflows, a solution that works better for me is displayplacer. This free open-source command line utility allows one to save their monitor configuration and restore it. Using this one can use Automator or any other service that can call command line to restore a monitor configuration. Like OP is doing, one can set up a configuration with screen mirroring turned on and another with screen mirroring turned off, then create a shortcut / automation to invoke either config.Bitten
P
29

Cmd+F1 appears to be a Mirror Displays shortcut in Snow Leopard. Don't know about Lion, etc, though.

Just tap it twice and see what happens (-:

For the people who prefer to set up their function keys to act in the old-fashioned way (not as brightness/sound controls etc.), it will be Cmd+Fn+F1

Prentiss answered 8/7, 2012 at 2:50 Comment(4)
And if you want to do this from the command line, you can use this free opensource tool to do it!Apostrophize
I pressed it once, and it mirrored, i pressed it again and it moved all the windows to the main display. Thanks!Blakeblakelee
It's worth mentioning that it's Cmd+Fn+F1 for the people who prefer using their function keys in the old-fashioned way.Crt
Doesn't work anymore. If I mirror displays on and off, it doesn't gather all windows in the main displaySocietal
T
7

On Lion you can toggle Mirror Displays using fn+Cmd+F1 (provided you are using the media control keys as default).

This also works on Snow Leopard and likely everything in between, also possibly further back.

Truong answered 2/5, 2012 at 10:29 Comment(1)
Using <kbd>fn</kbd> on Mountain Lion doesn't work for me on my MBP, but <kbd>Cmd</kbd>+<kbd>F1</kbd> alone does.Valletta
B
5

Here is a command-line script to do just that: http://zach.in.tu-clausthal.de/software/.

It's a little down the page under "Move Off-Screen Windows to the Main Screen".


-- Source: http://www.jonathanlaliberte.com/2007/10/19/move-all-windows-to-your-main-screen/
-- and: http://www.macosxhints.com/article.php?story=2007102012424539
--
-- Improvements:
-- +  code is more efficient and more elegant now
-- + windows are moved also, if they are "almost" completely off-screen 
--      (in the orig. version, they would be moved only if they were completely off-screen)
-- + windows are moved (if they are moved) to their closest position on-screen
--     (in the orig. version, they would be moved to a "home position" (0,22) )
-- Gabriel Zachmann, Jan 2008

-- Example list of processes to ignore: {"xGestures"} or {"xGestures", "OtherApp", ...}
property processesToIgnore : {"Typinator"}

-- 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
    repeat with i from 1 to count allProcesses
        --display dialog (name of (process i)) as string
        if not (processesToIgnore contains ((name of (process i)) as string)) then
            try
                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
                        set winSize to size of window x
                        set _w to item 1 of winSize
                        set _h to item 2 of winSize
                        --display dialog (name as string) & " - width: " & (_w as string) & " height: " & (_h as string)
                        
                        if (_x + _w < 40 or _y + _h < 50 or _x > screen_width - 40 or _y > screen_height - 40) then
                            
                            if (_x + _w < 40) then set _x to 0
                            if (_y + _h < 50) then set _y to 22
                            if (_x > screen_width - 40) then
                                set _x to screen_width - _w
                                if (_x < 0) then set _x to 0
                            end if
                            if (_y > screen_height - 40) then
                                set _y to screen_height - _h
                                if (_y < 22) then set _y to 22
                            end if
                            set position of window x to {_x, _y}
                            
                        end if
                    end repeat
                    
                end tell
            end try
        end if
    end repeat
end tell
Barrus answered 2/9, 2008 at 9:33 Comment(2)
The link is dead :(Ihab
Updated link: informatik.uni-bremen.de/~zach/software (I just googled for the phrase "Move Off-Screen Windows to the Main Screen" - with quotes.)Trowel
M
5

You can click the "Gather Windows" button in the Displays preference pane.

Monto answered 16/9, 2008 at 18:29 Comment(4)
@Zydeco That only gathers the windows from the Displays pref. :-) (At least, on 10.6, it fails to gather Terminal windows.)Nobility
Wow, this works like wonder, although I wonder if it is possible to create a shortcut (instead of multiple clicks to get there)Decompensation
Gah, yes, this is exactly what I want, but for applications I care about, not just the Displays screen!Overscrupulous
"Gather Windows" seems to be gone. apple.stackexchange.com/a/400291/277466 suggested bringing up Mission Control and just dragging the apps over. That was fast enough for me.Justajustemilieu
B
4

As you said, the best answer seems to be turning "Mirror Displays" on and off again. Afterwards, all windows will have been collected on the main screen, and the secondary screen will be empty.

screenshot

This is a bit cumbersome, but nothing else has worked for me in Lion.

Blinders answered 24/4, 2012 at 18:5 Comment(0)
T
2

There is an article on using AppleScript to do this at macosxtips.co.uk, and another at macosxhints.com.

Tetra answered 6/9, 2008 at 3:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.