Sunday, December 21, 2008

Screenshots of some useful Linux apps

Note: this is not a countdown. This is not even a countup.

1. Disk usage analyser:
This application shows how the disk space is being utilized among various files and folders in your system. It also includes a graphical, nested pie chart which shows in a straightforward manner how your disk is being used.

2. Amarok:
Amarok is one of the better of the (30+) music players available for Linux.
While the UI of Amarok has actually been criticized for being too clunky or something, I personally think this looks good. My only complaint is that between version 1 and version 2 the app seems to have misplaced its graphic equalizer.

3. Clock:
This is the default clock available in gnome. This sits as a time display on your task bar, until you click on it. Then, it displays a calendar, a world map with night/day shown, and local times and weather of any locations you add to it.

4. Brasero:
Brasero gives you a very simple interface to create and burn any type of cd/dvd/.

5. Panel monitors:
You can add applets to the panel which monitor CPU usage, Memory, Network usage, etc. I have set this up as something which becomes visible on mouseover.
Note the time on the analog clock: this was actually taken after the screen shot where it said 5:05 pm. In this one it's 5:15:27 pm; the second hand is hiding the hour hand.

oh yeah, btw, check out my wallpaper!

Sunday, December 14, 2008

Fun with Linux (Too technical, you can skip this)

The best thing about linux is that you always discover new things while working with it. For example, I recently discovered that you can open GUI windows from the shell prompt by using a command called zenity. This was very interesting as it widens the gap between console programming (which every student is taught) and GUI programming (which a developer has to know to make anything useful) considerably.

Now I could do stuff like display my own notifications:


This was done by a simple command like this:
zenity --info --text "Hello World"

but of course, a window showing "Hello World" is not very useful.

Ever wonder why all computer language books give a "hello world" program as their first example? I mean who wants a program that says hello world and does nothing else? See, this is not the way to attract potential new programmers to the world of coding...


So, anyway, I decided to make a practical app to see what I can do with this... but what to do? I got the idea after piping the output of ps to a text box:



Hmm, I could make my own process manager, which would be a most rudimentary app to hunt and kill processes running. The element I would be using is a list box (zenity --list). This unfortunately does not allow output to be piped in. So I had to write a perl script which converts stdin to command line option for a zenity list:


#!/usr/bin/perl -w
use strict;
use Data::Dumper;

#my $seperator="\t"; #TODO: pass this as command line option.
my @columns;

my $line = <stdin>; #Input comes from standard input. Caller should redirect.
chomp $line;
$line =~ s/^\s+//;
@columns = split (/\s+/, $line);

my $columnCount = $#columns;

foreach my $column (@columns) {
print qq{ --column $column };
}

while ($line = <stdin>) {
chomp $line;
print qq{FALSE $line };
}
The alert reader will notice that this script will convert any tabular input into command line option for a zenity list - maximum reusability!

All that remains is to pipe the out of ps and take the output of zenity as parameter for kill:


#!/bin/bash
listWindow() {
psParams=pid,ppid,comm,time,pcpu,stat #Edit this to modify columns
zenity --list --text="Select the processes to kill:" --width 640 --height 480 --checklist --separator=" " --column Select \
$(ps -u $USER -o $psParams\
| tee >(zenity --progress --pulsate --auto-close)|perl /home/prasanna/bin/mkzenitylist.pl)
}

pid=$(listWindow)
while [[ -n "${pid}" ]]; do
zenity --question --text "Really kill processes with pids: $pid?" && (kill $pid ||
for i in $pid; do
if ps p $i >/dev/null 2>/dev/null; then
zenity --question --text "$i did not die: force kill?" && kill -9 $i
fi
done)
pid=$(listWindow)
done
Voila! One task manager ready! On launching, the first screen looks something like this:
Let's say I select 'gedit' and click ok:
Clicking ok will kill the process, and take me back to first screen. Clicking cancel would take me back to the original screen without killing anything.

This obviously is not the best process manager you can think of; It's not even real time (I certainly don't use this - I use the default task manager that comes with the OS :) )
But, it is nevertheless, usable. And that was the point of this exercise: to make a GUI app that is simple and usable in a real world scenario.