Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Here’s something that sucks:

  1. Plug in external monitor to laptop (Mac OS X Leopard in my case).
  2. Arrange your windows to have the IDE on one screen and browser on another. (Etc etc. Resize, rearrange, fuss, fuss, fuss.)
  3. Unplug monitor to run to a meeting, or whatever.
  4. Goto 1.

I’d like to replace step 2 with “computer remembers exactly how I had it and just puts it back that way”.

(I personally only need a solution for Mac but collecting solutions for other systems here might be useful to others. I’m sure it’s a common problem.)

share|improve this question

migrated from stackoverflow.com Apr 3 at 2:53

This question came from our site for professional and enthusiast programmers.

8 Answers 8

up vote 37 down vote accepted

You guys need to have a look at Stay by Cordless Dog. I believe it does exactly what you're looking for.

share|improve this answer
2  
I tried this. It doesn't work for X11 windows but otherwise seems to be as advertised. Thanks for the pointer! It may be that this is the closest we've got to a solution for Mac currently. –  dreeves Dec 5 '10 at 20:31
    
X11 windows aren't "real" NSWindow instances (at least they weren't last time I checked) so it's not a big surprise that Stay wants nothing to do with them :) Glad it worked out otherwise! –  Tony Arnold Feb 1 '11 at 11:38
    
This looks good, but it is not working with fullscreen apps in Lion. I have Safari in fullscreen mode when I have 1 display and after I attach 2nd display, I want to exit fullscreen and move Safari to second display. Stay does not move any fullscreen app. –  vasco Jun 4 '12 at 8:05

I have solved this with a small applescript + the small freeware utility quicksilver.

1. save this small applescript in a location that will not change on your computer:

try
tell application "Adium"
    activate
    tell window "contacts"
        set the bounds to {1281, 200, 1460, 850}
    end tell
    tell chat windows
        set the bounds to {1281, 800, 1800, 1200}
    end tell

end tell
end try


try
tell application "iTunes"
    activate
    set the bounds of the first window to {1750, 520, 2700, 1150}
end tell
end try

try
tell application "Terminal"
    activate
    set the bounds of the first window to {2450, 320, 3180, 950}
end tell
end try

try
tell application "Firefox"
    activate
    set the bounds of the first window to {1460, 20, 2800, 950}
end tell
end try

2. You will need to customize which applications you want on your monitor and the window bounds the way you like them. I'm a programmer and the above configuration is how i run my second monitor.

3. install quicksilver (http://www.blacktree.com/?quicksilver) (i chose to make it not visible in the dock, and just run as a small taskbar daemon)

4. setup a keycommand in quicksilver, and drag and drop your applescript from step 1 into the window as the action to perform. I bound it to CMD+SHIFT+A. works great!

share|improve this answer
2  
Not particularly scalable if you have a good number of applications to manage. Nor is it easy to manage! Hard-coding bounds really is no fun. –  fatuhoku Dec 15 '12 at 18:02
    
This is a great solution -- thank you. –  toddsler Feb 12 '13 at 22:28
    
Can you set the desktop that the application appears on? –  dangerousdave Jan 24 at 12:40

http://www.n8gray.org/code/forget-me-not/ for OSX 10.4

share|improve this answer
    
Note that this doesn't work for OS X 10.5 currently. –  dreeves Jul 24 '09 at 18:16

Slate is a very powerful free Mac app that does exactly what you want. When you plug in your secondary monitor, it automatically detects the new monitor, and all of your windows will be moved and resized just the way you like them. You can define custom positions and sizes for all of your applications, including full screen, half screen, and grid-based.

One of the coolest things about Slate is that you can define different layouts based on how many monitors you have connected. For example, if you are using your laptop by itself, you might want to have all of your apps filling the whole screen. But when you have a larger secondary monitor, you might want to split up your screen between your browser, mail, and music. Slate does this easily.

You can also define keyboard shortcuts for specific layouts and actions such as nudging and resizing windows by a certain percentage.

Below is my configuration file. I keep all of my apps at full screen on all of my monitors, but you can change it to make them half or some other size:

# Monitor Aliases
alias mon-laptop    0    # variable for my laptop monitor
alias mon-hp        1    # my external HP monitor

# Window Position Regions
alias hp-full        move screenOriginX;screenOriginY screenSizeX;screenSizeY         ${mon-hp}
alias hp-left        move screenOriginX;screenOriginY screenSizeX/2;screenSizeY         ${mon-hp}
alias hp-right       move screenOriginX+screenSizeX/2;screenOriginY screenSizeX/2;screenSizeY         ${mon-hp}
alias laptop-full        move screenOriginX;screenOriginY screenSizeX;screenSizeY         ${mon-laptop}
alias laptop-left        move screenOriginX;screenOriginY screenSizeX/2;screenSizeY         ${mon-laptop}
alias laptop-right       move screenOriginX+screenSizeX/2;screenOriginY screenSizeX/2;screenSizeY         ${mon-laptop}
alias laptop-righttop    move screenOriginX+screenSizeX/2;screenOriginY screenSizeX/2;screenSizeY/2       ${mon-laptop}
alias laptop-rightbottom move screenOriginX+screenSizeX/2;screenOriginY+screenSizeY/2    screenSizeX/2;screenSizeY/2       ${mon-laptop}

# Window layouts for when I have 2 monitors
layout 2monitor 'Google Chrome':REPEAT ${hp-full}
layout 2monitor 'iCal':REPEAT ${hp-full}
layout 2monitor 'Coda':REPEAT ${hp-full}
layout 2monitor 'Mail':REPEAT ${laptop-full}
layout 2monitor 'Rdio':REPEAT ${laptop-full}
layout 2monitor 'Spotify':REPEAT ${laptop-full}
layout 2monitor 'Evernote':REPEAT ${laptop-full}

# Single monitor window layouts
layout 1monitor 'Google Chrome':REPEAT ${laptop-full}
layout 1monitor 'iCal':REPEAT ${laptop-full}
layout 1monitor 'Coda':REPEAT ${laptop-full}
layout 1monitor 'Mail':REPEAT ${laptop-full}
layout 1monitor 'Rdio':REPEAT ${laptop-full}
layout 1monitor 'Spotify':REPEAT ${laptop-full}
layout 1monitor 'Evernote':REPEAT ${laptop-full}

# Keyboard shortcuts for each layout
bind l:shift;ctrl layout 2monitor
bind g:shift;ctrl grid padding:5 0:2,1 1:2,2

# Auto-detect when a monitor is plugged in or out
default 2monitor count:2
default 1monitor count:1

Here is the list of features from Slate's GitHub page:

  • Highly customizable
  • Bind keystrokes to:
    • move and/or resize windows
    • directionally focus windows
    • activate preset layouts
    • create, delete, and activate snapshots of the current state of windows
  • Set default layouts for different monitor configurations which will activate when that configuration is detected.
  • Window Hints: an intuitive way to change window focus
  • [Beta] A better, more customizable, application switcher.

Here is a great tutorial on how to get the most out of Slate.

share|improve this answer
    
Can it remember how the windows were positioned from when external monitors where last plugged in and just restore them? The app "Stay" almost does this but it keeps failing to remember windows (particularly Chrome) so I'm still looking for something better. –  dreeves Jul 30 at 21:48
    
@dreeves Yes, it works for me. I just successfully did that manually, using Slate’s menu items “Take Snapshot” and “Activate Snapshot”; if you click them before and after you put your computer to sleep, you will save and restore all your window positions. From the docs, it looks like Slate can do the “Activate Snapshot” automatically with its default directive. I don’t know if you can automate the “Take Snapshot” part. –  Rory O'Kane Sep 15 at 21:51

Before you unplug the monitor, close everything that's not entirely on the main monitor. Applications generally save their state (including window placement) when they close, and read it when they open, so if the second monitor is present at both of those times you should be fine.

You can take advantage of applications which allow more than one instance to be open at a time, but only save state on close. Close the multi-monitor instance (which causes the state to be saved). Unplug the second monitor. If you have a second instance running, it should be repositioned onto the main monitor, or you can start another instance. Don't close this instance before plugging the second monitor in again and starting another instance (which would then read the multi-monitor configuration on startup). Then you can quit the single-monitor instance (saving that state), and then the multi-monitor instance (overwriting the single-monitor state).

A more complex option might include figuring out where the state is saved, backing it up, and writing a batch file / script to restore it before opening the application, which would allow you to make a link to do this automatically when you start the application.

Finally, there may be such a utility for your platform, or writing one might not be too complex. For Windows, there is a program called ShiftWindow that can reposition windows either on application startup or on a certain hot-key. I'm afraid I don't know MacOS well enough to say if a similar utility exists. This is probably the ideal solution, second only to having the OS support such a thing directly.

share|improve this answer
1  
Thanks! Not the answer I was hoping for but a good lead! –  dreeves Feb 13 '09 at 13:53
    
did you finally find a solution for this? –  Werner Oct 18 '10 at 19:45

At least on Windows, many apps will restore themselves if you maximize them before switching monitors. Leave them alone while you're in the meeting, then restore them after reconnecting.

It's still an incomplete fix (and hassle) but it's the only thing I know to do if I want some chance of resurrecting my carefully placed windows. ShiftWindow sounds intriguing though...

And if you go from two monitors down to one, Alt+Spacebar+M then arrowkeys is a life-saver (Windows again, sorry) if you "lose" your windows.

share|improve this answer

http://www.irradiatedsoftware.com/twoup/index.html

I found this via Lifehacker, and it works great for me. I'm using the pro version SizeUp as opposed to the free TwoUp, and it's perfect.

share|improve this answer
    
Are you saying this solves the problem I posed though? The page you linked to doesn't seem to mention anything about that. –  dreeves Jul 24 '09 at 18:15
    
No, this doesn’t solve the problem at all. SizeUp makes it quicker to move a window where you want it, but you still have to manually switch between each window and tell SizeUp where you want to move each one. –  Rory O'Kane Sep 15 at 21:59

I'm a Windows user and was looking how to switch off the new Windows 7 feature to move all windows away from the unplugged external monitor. I found the receipt (for ATI video cards) to set all DMMEnableDDCPolling values in registry to 0. It disables the automatical check if the monitor is switched off. Now if the monitor is unplugged and plugged again, all windows keeps in the same position.

Here's the answer which helped me: http://superuser.com/questions/120983/how-to-disable-monitor-auto-detection-in-windows-7 (answer by Alex)

share|improve this answer
    
This has nothing to do with Mac? –  Walt Feb 26 '13 at 15:43
1  
No.. but the question was tagged also as "windows" (although maybe the OP referred to program windows ;)). Anyway, for Windows there are couple of handy utilities for the task. I personally use Basta's ZMover and it has worked well. Another alternative is DeskSoft's WindowManager. But these won't of course help OSX users. –  Ville Sep 3 '13 at 15:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.