skip to main bit
a man slumped on his desk, from 'The Sleep of Reason Produces



rag and bone scripts: switchto

So I feel a bit bad because I have two half-written long thoughtful posts, but this evening was games night at the EFF’s hollowed-out mountain headquarters, and after a bit too much Settlers of Cataan, beer, Rock Band, and beer, I strangely cannot be bothered to finish those entries. I will just repeat for the record that you have not seen rules lawyering until you have seen EFF’s litigation team play AD&D. I still admire Quinn for daring to DM them.

Anyway, instead, let me fob you off with a couple of tiny hacks I use pretty frequently on my Linux desktop.

They all gank their usefulness from wmctrl, which is a fantastic command line utility for almost any Linux desktop, and lets you control windows and focus from the command line. You can install it from that webpage, or just do apt-get install wmctrl on Debian/Ubuntu.

I save the above script as ‘switchto’, and use it in GNOME’s keyboard shortcuts like this:

That should set some options in the standard GNOME editor to run
switchto "Mozilla Firefox" "firefox"
whenever you hit Alt-F. It works with metacity and compiz, which is probably what you’re running with GNOME. Other desktops will have other ways to create keyboard shortcuts — I seem to remember that KDE’s one rocks.

Now, whenever I hit Alt-F on my keyboard, my desktop will switch focus to the first window it finds with “Mozilla Firefox” in its name. If it can’t find one (ie I’m not yet running Firefox), it starts it up for me. One key press gives me a Firefox window, either way. Here’s another one:

This is the poor man’s QuickSilver — it pops up a box, and switches your focus to a window that matches the text you type into it. It needs a program called Zenity which comes by default on most GNOME desktops.

Actually, I don’t actually use the second of those that much, but I do have a bunch of scripts like the first, setting up command keys to always switch to certain programs like the Terminal (try switchto "termi"), or IRC or Kontact. Your fingers quickly learn the motion, and finding your key applications even in a mass of desktops becomes instinctive.

I’ve always felt that that was the real power of QuickSilver as a window finder — Alt-Tab never lets you learn a consistent muscle memory to switch to a particular program, so you’re constantly derailing your thought by peering at icons to navigate around. I’d also encourage you to play around with wmctrl on the command line — you may be able to think of other desktop tricks that you can turn into simple keypresses.

5 Responses to “rag and bone scripts: switchto”

  1. Tomas Krag Says:

    This is brilliant. I’ve been looking at wmctrl for a while, with a nagging feeling that it could be really useful, but without the inspiration to see how. Now i know. thanks.

  2. Justin Mason Says:

    I always love reading about these hacks, alright.

    My version is keyboard shortcuts for moving windows left and right — I can quickly rattle a window out of the way, or into a desired location against one side of one of my screens. “Pack Window to the Right” and “Pack Window to the Left” in KDE’s “kwin” window manager, rebindable through the “Regional & Accessibility” -> “Keyboard Shortcuts” -> “Global Shortcuts” in the KDE control center.

  3. anon Says:

    s/gconf-editor/gconftool/, at least on my Ubuntu system. Also, your funny quotes and fancy emdash make copy-pasting not work

  4. Danny O'Brien Says:

    Thanks anon, yeah, hopefully all fixed.

  5. shadowfirebird Says:

    gnome-do is pretty good. If you run gnome.

    Not as good as QS, obviously…


petit disclaimer:
My employer has enough opinions of its own, without having to have mine too.