I used to use a Windows 7 machine extensively, and one thing I really loved was the ability to use a Windows Key + Number keyboard shortcut to switch to apps on my taskbar. That is, if I pressed Win+1, it would launch the first app on my taskbar, or switch to it if it was already open. I still instinctively want to use such shortcuts even when I'm on Linux. Fortunately, Openbox is configurable like crazy, and this is very easy to replicate. Here are the steps to set it up:
- Install the wmctrl utility. In Arch Linux, you can do this in the terminal by typing: sudo pacman -S wmctrl
- Put my Perl script below in a convenient place (I have mine in ~/Scripts, under the name winswitch.pl)
- Run the Openbox key bindings editor (obkey command or, in ArchBang, right click on the desktop and choose Preferences->Open Box->Key Bindings)
- Create a new key binding for W-1 (which means Windows Key + 1) and bind it to the command: perl ~/wherever/you/put/it/winswitch.pl 1
- Do the same for the other number keys if you like... e.g. you can bind W-2 to: perl ~/wherever/you/put/it/winswitch.pl 2
The functionality isn't exactly like Windows 7, of course... The keyboard shortcut won't actually launch anything, it will only switch to a given window. It also won't remember that a certain window or application is always a given number -- e.g. on my Windows 7 machine, Win+1 was always Google Chrome, and Win+3 was always my Cygwin Terminal. Still, the task switching functionality is very intuitive, since Win+1 will switch to the first window you see on the taskbar, Win+2 will switch to the second one, and so on. Here's the script:
#!/usr/bin/perl my $switchto = shift; my @winlist = `wmctrl -l`; $winlist[$switchto] =~ /^(0x[0-9a-f]+)\s/; `wmctrl -i -a $1` if($1);If you're feeling really geeky, here are some possibilities to expand on this or make it better:
- Reduce some CPU/process overhead by re-writing this as a bash script using awk.
- Modify the script so that certain numbers always represent a given app, and 1) launch the app if it's not running, or 2) raise the app's window if it is already running. This would be closer to the Windows 7 functionality.
#!/bin/bash let SWITCHTO=$1+1 wmctrl -i -a `wmctrl -l | tail -n +$SWITCHTO | head -n 1 | cut -d " " -f 1` unset SWITCHTO