Tricking Spaces Not to Switch

Spaces is one of the features of Leopard that I've been looking forward to. I used Desktop Manager for a long time in Tiger, but it was no longer maintained (it was a wonder it still worked on Intel macs!) and it had a few obvious and annoying bugs. I'm really glad Apple implemented desktop switching, and they mostly did a good job of it.

There are, however, problems. Apart from a nasty bug in 10.5.0 (windows would sometimes disappear forever), there is one thing I really don't like: when you switch to another application, Spaces might decide to move you to another desktop, if that application has a window there. It should not move you, ever. Desktops should not switch without me explicitly asking for it.

One of the most common causes of automatic switching was opening a new browser (or iTerm or TextMate) window, because I would have to bring up the application. So what I did was write a really simple AppleScript and invoke it with a Quicksilver keyboard shortcut.

tell application "Safari"
    make new document
    activate
end tell

This works because new windows are always created on the current desktop, and Safari only "activates" after the window is created, so it doesn't switch. I'm still figuring out this AppleScript language; the make new document command only works for Safari. So far I haven't been able to figure out how to open a TextMate or iTerm window, but I'm working on it. :)