Friday, April 19, 2013

Win+Number Taskbar Switching in Openbox



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
Now you can press the Windows Key + a number key and switch to that window on your taskbar.

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.
Update: Okay, I got geeky and re-wrote this as a bash script, for less overhead:

#!/bin/bash
let SWITCHTO=$1+1
wmctrl -i -a `wmctrl -l | tail -n +$SWITCHTO | head -n 1 | cut -d " " -f 1`
unset SWITCHTO

Tuesday, April 16, 2013

Sort Installed Packages by Size in Arch Linux (pacman)

In an effort to keep my new Arch Linux installation clean and slim, I wanted to find an easy way to see all the packages I have installed and just how big each one is. I googled around and found a number of scripts in Python, bash, etc. but none that did quite what I wanted and gave human-readable output. My biggest issue was that all the scripts I found outputted the size in kilobytes, which is not always very visually friendly.

Below is my Perl script for accomplishing this. It will spit out a list of every single package installed, sorted from smallest to largest, and formatted with numbers in human-readable format (e.g. 224M instead of 230206). I recommend running this with the tail command (perl pacsize.pl | tail) to find out your top 10 biggest offenders in terms of package size. Happy package managing!

#!/usr/bin/perl
my @pacout = `pacman -Qi|awk '/^Installed Size/{print int(\$4), name} /^Name/{name=\$3}' | sort -h`;
my @b = ('K', 'M', 'G');

foreach my $pacitem(@pacout) {
     $pacitem =~ /^\s*([0-9]+)\s(.+)$/;
     my ($psize, $pname) = ($1, $2);
     my $psizeb = int(log($psize) / log(1024));

     for (my $i = 0; $i < $psizeb; $i++) {
          $psize = sprintf("%3d", ($psize / 1024));
     }

     print "$psize" . $b[$psizeb] . " $pname\n";
}

Sunday, April 14, 2013

HOWTO: Wireless on Toshiba M35X-S311

Laptop + Wireless Mouse 5-16-09 I'm posting this partly as a reminder to myself, should I ever need to do this again, and also as something helpful that someone else may stumble across in a Google search.

This very brief HOWTO outlines what for me is the most critical part of getting Linux working on a laptop -- wireless. Specifically in this case, getting the wifi to work on my ancient Toshiba M35X.

Please note that this HOWTO is specifically oriented toward ArchBang, which is a variant of Arch Linux. I imagine the steps will be largely similar under Arch Linux; in broad terms they will also be similar under other Linux distributions, but you will have to use other tools (e.g. under Ubuntu you'd have to use apt-get instead of pacman).

Your mileage may vary, but I'll tell you one thing -- the instructions below are far better than anything I could find stumbling around on Google, trying to figure this out for myself the first time!



The problem: Out-of-the-box, ArchBang Linux includes the ipw2200 module, which is what you need for the wireless adapter in the M35X. Unfortunately, this module needs firmware which is not included with ArchBang.

The solution: Install the ipw2200-fw package, unload and reload the ipw2200 module.

The wrinkle: This is perhaps easier said than done -- you need internet access to install the firmware, but you need the firmware to get on the internet. That is, unless you do one of two things:
  1. Connect your Toshiba directly to your network or modem using an ethernet cable, so that you have internet access to download the package directly.

    ** OR **
  2. On another PC, download the ipw2200-fw package file and put it on some media you can access right after you install Linux (e.g. put it on a USB flash drive).
How to it: I did option 1, because it involved the fewest steps. Option 2 is certainly viable, but I have not done it and will not document it here. Here are the steps that worked for me:
  1. Connect your Toshiba to your network/modem using an ethernet cable.
  2. Open a Terminal window (right-click on the desktop and choose "Terminal").
  3. Edit the /etc/pacman.d/mirrorlist file with the editor of your choice (if you're a Linux rookie, the command for this would be: sudo nano /etc/pacman.d/mirrorlist)
  4. Remove the # sign from in front of one of the mirrors listed for your country. Some work better than others, so you may have to come back to this step if you have problems further on in these instructions.
  5. Save your changes to the mirrorlist file.
  6. Next, execute the following commands in the terminal:
    • sudo pacman -Syyu
      (this
      will go out onto the internet and update your package database to the latest and greatest, so you can download and install packages)
    • sudo pacman -S ipw2200-fw
      (this downloads the firmware for the ipw2200 driver
      )
    • sudo rmmod ipw2200
      (this unloads the ipw2200 kernel module, which probably loaded automatically when you booted Linux
      )
    •  sudo modprobe ipw2200
      (this loads the ipw2200 module again
      )
If all worked the way it's supposed to, you can now left-click on the NetworkManager icon at the bottom of your screen, and you should see a list of wireless networks nearby. Choose the network you want, enter a password if necessary, and voila!

Make sure to unplug your ethernet connection before you get too far, to make sure that you are indeed functioning solely through wireless.

Saturday, February 23, 2013

Bike Route: Lynnewood Loop

I put together a simple route this morning, which I call the Lynnewood Loop. You can scroll down for some important notes and highlights -- and you can click on the map below to access the Google Maps version which you can zoom in and out of, print, etc.

This route starts at Taylor Park (A), briefly heads south on Pennsylvania until it meets the Paseo de las Montanas bike trail (opposite Winrock Loop), and heads east. Continuing along this trail leads across Moon and Indian School, and through Snow Park. At Morris (the white dot on the map), this route follows the fork northeast (left) toward Lynnewood Park (B), a nice resting point.

After Lynnewood Park, the trail connects to a bridge that crosses to the east side of Tramway. Heading south on the Tramway bike trail, the route then turns west on Indian School (C). This brief ride along Indian School starts out with a two-lane road and no bike lane, but traffic is light, and a bike lane eventually develops. The route involves a dogleg back onto the Paseo de las Montanas trail to where the fork comes together at Morris. The remainder of the route to Taylor Park (D) is the reverse of the beginning of the ride.



Highlights and notes: