Use Your MacBook Pro with an External Monitor Without Sleeping

So, in a similar vein as to what pushed me to write my Applescript to resize windows, I’ve been looking at what to do about going from using the LCD on the MacBook pro to an external monitor.  Now, everyone knows that in order to use an external display, you have to connect the display adapter while the notebook is closed, plug in an external keyboard (and your power supply), and press a button, and boom, you’ve got external display action at your monitor’s native resolution.  But what if you don’t want to wait the ten seconds or so it takes to go from awake to asleep?  Messing with it, I was happy to note that the following procedure seems to work:

  1. Plug in the external display, your keyboard/mouse, your power supply, etc—with your notebook open.  The external display will mirror your notebook’s LCD, at its resolution (if supported by the display.  If it isn’t, you’ll get the highest common denominator, I think).
  2. Close your notebook cover so the display turns off.
  3. Immediately open the notebook cover, then close it just as soon, then push a button on your keyboard.
  4. Presto! Your MacBook Pro should see the display and change the resolution how you want it.

I’ve only tested this on my machine, so let me know in the comments if it works/doesn’t work or if you have a better way.

Resize Your Windows Automatically for Different Resolutions

I use my MacBook Pro in a few different scenarios: by itself, plugged in to a 21” Apple Cinema Display, or plugged in to a 24” Dell 2405FPW.  I’m also rather OCD; I prefer my Firefox/Safari, Mail.app, and Vienna windows to be centered, stretch from the menu bar to the top of my Dock, and be a certain width.  I created a small AppleScript to auto-detect my resolution and size the windows accordingly:

tell application "Finder" set screen_resolution to bounds of window of desktop set screen_width to item 3 of screen_resolution set screen_height to item 4 of screen_resolution end tell tell application "System Events" to tell process "Dock" set dock_dimensions to size in list 1 set dock_height to item 2 of dock_dimensions end tell set desired_width to 1400 set side_space to screen_width - desired_width set left_bound to (side_space / 2) set right_bound to left_bound + desired_width set bottom_bound to screen_height - dock_height set top_bound to 22 (* for the menu bar *) try tell application "iTunes" activate set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound} end tell end try try tell application "Firefox" activate set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound} end tell end try try tell application "Mail" activate set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound} end tell end try try tell application "Vienna" activate set the bounds of the first window to {left_bound, top_bound, right_bound, bottom_bound} end tell end try

With that in place, I saved it as an application in ~/Applications, and put it in my Dock. Now, whenever I change resolutions, I just click the button and everything is how I like it.

To change the script, you should be able to add any application with an AppleScript dictionary that supports moving and sizing the window.  The numbers I’ve used make the windows 1,400px wide, and the height that you want will depend on the size of your Dock. The script moves windows to the center, desired_width wide, and from the menubar to the Dock.

Note: I have had some trouble recently; sometimes when I change my resolution the AppleScript doesn’t pick it up.  To combat this, I told the Displays System Preferences pane to keep its icon in the menu bar; when my script uses the incorrect resolution, I change my screen resolution then change it back, which is enough for the script to detect the change.

Update 2008-05-28: Made some usability changes. Details here.