Robbie Allen
 
Web rallenhome.com

 Links

  Home
  About Me
  Books
  Essays
  Articles
  Scripting
  Public Speaking
  Contact Me

 


 Other Blogs

  Publishing Hacks

  UNC Basketball


 Archived Blogs

  MIT Musings

  Active Directory
    Cookbook


Technorati Profile

This site has moved to robbieallen.com. Update your bookmarks!

Extending the desktop (via a script)

Saturday, August 26, 2006

Over the last few months, several articles have been written about the productivity boost associated with having two (or more) monitors (e.g., NYTimes). I've had dual monitors at work and home for two months and I love it. Extending the desktop environment over much larger screen real estate means you don't have to constantly switch between various applications. I can have my email, IM, or browsers up in one monitor while I read a document or code in an IDE in another.

One pain associated with doing this on Windows XP is the fact that you have to go into the Display Properties, select the second montior, and check "Extend my Windows desktop onto this monitor.". This is a pain because sometimes when I undock my laptop, it won't recognize that the second monitor isn't attached. And even if it does recognize that it is disconnected, when I hook up to the docking station again I have to go back into the properties and re-check the "extend my desktop" box.

I figured there had to be a way to script this setting. I found the ChangeDisplaySettingsEx API, but it wasn't easily scriptable. Next I looked at simulating GUI movements. A quick Google search led me to AutoIt, which looked like exactly what I needed. Plus it is free!

AutoIt was very easy to install and use. It only took me a couple minutes to create this script which will toggle the 'extend my desktop' box:

Run("C:\WINDOWS\system32\control.exe desk.cpl,@0,3")
WinWaitActive("Display Properties")
Send("{TAB}")
Send("{DOWN}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{SPACE}")
Send("{ENTER}")


It's a hack, but it works great. Even better than that, AutoIt has an option to compile scripts to executables. This won't work for everyone, but here is my compiled script.



  On the Web:

      Amazon Connect
      LinkedIn
      Flickr
      Technorati
      Facebook

  Notes of Note:

  Recent Posts:   Archives: