DisplayWatcher: Run Scripts based on Mac Display Arrangement

by James Elliott

Related link: http://www.brunchboy.com/displaywatcher.shtml



One of my favorite features of Mac OS is how easily you can connect multiple displays, and spread your desktop between them. Heck, Microsoft even figured this one out after a decade or so. This means that when I'm at home, I like to have my PowerBook plugged into a nice big display, which has plenty of room to show the dock, while putting palettes like my DragThing window on the built-in display off to the side.

When I'm on the road, I have less real estate, so I like to hide the dock, and position a more compact DragThing configuration at the bottom of the screen, showing its own process dock.

Mac OS is very good about remembering the physical relationships between different displays that I connect, but I was still spending more time than I liked manually toggling the dock and switching between DragThing settings. So, being a typical proactively lazy geek, I decided to build a tool to do this for me. It would be a great excuse to learn a little Cocoa programming.

I've been using DisplayWatcher for a few months now, but I still get a little thrill out of watching the dock and DragThing reconfigure themselves, as if by magic, when I plug in or disconnect an external monitor. I also added the ability to run a script whenever my PowerBook wakes up from sleep--I use this to re-establish SSH tunnels for accessing and sending mail through my personal and corporate IMAP servers, CVS and the like. Now I'm far less reluctant to put my machine to sleep or move to other rooms, because there is no more hassle involved. That's how a laptop should work!

Since DisplayWatcher seems very stable, I'm making it available for others who might find it useful. For now it is a binary-only download, but when I have time to write up some in-depth explanation, I hope to release it as open source as well. I certainly found it an instructive project myself, and would like to share that aspect as well.

If you're interested, follow the URL associated with this posting and check out the instructions, or download it and play with it.

If you download and use it, please let me know... especially if you come up with interesting new scenarios!


7 Comments

James_Elliott
2004-07-11 22:20:01
Whoops, had to post a version 1.0.1
I couldn't resist making some very nice improvements to the code right before posting it this weekend. My friend Mike Trent (as seen on CocoaDev.com) pointed out that there are now high-level AppKit events to replace some nasty low-level hackery I was using, which made the source a lot simpler, and enabled me to fix an irritating if minor limitation of the preference pane. But, that means the version I posted wasn't the version I'd tested for so long, and it turned out I had broken the "on wake" detection. Dohh!


If you downloaded version 1.0.0 on Sunday, July 11, please replace it with version 1.0.1, and accept my humble apologies (and stunned congratulations for having found this app so quickly)!

UR
2004-07-11 22:24:58
Nice application, but the scripts are not found
The application downloads fine, but your script examples
don't seem to be available at


http://www.brunchboy.com/Archive/dwScripts.zip


Thanks for making this application available. I'm switching
from my CRT display (using the PowerBook lid closed) to the
LCD daily, and reconfiguring is slightly cumbersome.

James_Elliott
2004-07-11 22:32:49
Nice application, but the scripts are not found
Thanks for pointing this out. Somehow DreamWeaver hadn't noticed them as a "dependent file", so I had to push them manually. They should be there now.


If you've got version 1.0, please also update to version 1.0.1 as noted in my "oops" below!

UR
2004-07-11 22:45:34
Nice application, but the scripts are not found
Thanks! The scripts are stored as applications,
how can I open them for editing? I tried opening
them in Script Editor, but it just tried to execute
them.
UR
2004-07-12 02:15:38
Nice application, but the scripts are not found
Answer to myself: Rename the script so that the suffix is .scpt, and then you can edit it just fine.
James_Elliott
2004-07-12 05:56:56
Nice application, but the scripts are not found
Another answer: You can drag the script applets on top of Script Editor rather than double-clicking them, or you can use File->Open within Script Editor.


At least, those approaches worked for me... Did your results differ?

James_Elliott
2004-07-13 14:51:34
Sigh. Take three? Version 1.0.2 now available.
I hope the third time is the charm. Apparently the builds that I posted previously were compiled for debugging, in such a way that they would run properly only on my own machine. That's what happens when you're just learning how to use a development environment...


I've been told that the 1.0.2 builds do run, so please give them a try if you've had trouble with the others.