December 19th, 2006

There are many like it. This one is mine.

Ever since I first started using a window manager with virtual desktops workspaces, I've segregated certain types of activity into certain workspaces. Mail reading goes on workspace one. Web browsing goes on workspace two. Emacs hacking goes on workspace three. A bunch of miscellaneous activities go on workspace four. If I'm feeling frisky I may do some PDF viewing on workspace five, but 95% of my time is spent on those four workspaces.

Past window managers made it pretty easy to force, say, new web browser windows to pop up in the web browsing workspace. But then Metacity arrived, and cut out all that sort of orthogonal functionality, and left it to other utilities to make it happen.

As far as I know Devil's Pie is a fine way to replace the functionality. But I happen to run an older distro of in a few places, and Devil's Pie requires GNOME version flashy point flashy, and it won't work with what I have.

So, after a little poking at the WM interoperability standard and reading a bunch of X man pages, I wrote the tiny switch-workspace (188 lines, depends on: X development headers and libs).

Usage: switch-workspace workspace-number [command-and-args]

Switches to workspace workspace-number. If command-and-args are given, execs them via execvp.

I use it like so:

switch-workspace 1 firefox -remote 'openURL(http://foo.com/, new-tab)'

I also made a snippet of elisp that calls it:

(defun switch-to-workspace (n)
  (interactive "NWhich workspace: ")
  (call-process "switch-workspace" nil nil nil (format "%d" n)))

Enjoy!

update wmctrl not only does this, it also supports fun stuff involving all the other window manager control protocols, and provides a nice summary of other options. Go check it out!