#!/usr/bin/perl
# Script: launcher.pl
# Version: 0.1
# Author: Rick Saunders
# Date: 28 Feb, 2005
# A little perl thing I use to keep handy commands that I run all
# the time. Put it in /usr/bin, make a keyboard shortcut to it and
# build a config file in your home directory that looks like:
#
# -
# KCalc
# kcalc
#
# .. repeat as many items as you want..
#
use strict;
use Gtk2;
my $login = getlogin || getpwuid($<);
my $homedir = "/home/" . $login;
my $config_file = "$homedir/.launcherrc";
my $false = 0;
my $true = 1;
my @clist;
open( CONFIG, $config_file ) or die "Can't open configuration file";
my @entries = ;
close( CONFIG );
Gtk2->init;
my $main_window = Gtk2::Window->new( 'toplevel' );
$main_window->set_title( "Ozzzy's Launcher" );
$main_window->set_default_size( 300, 30 );
$main_window->signal_connect( 'delete_event' => sub { Gtk2->main_quit(); } );
my $launch_vbox = Gtk2::VBox->new( $false, 0 );
$main_window->add( $launch_vbox );
$launch_vbox->show();
my $name;
my $command;
my $button;
my @names;
my @commands;
# Strips all leading/trailing white spaces, blank lines and
# new-line characters from the input entries
#----------------------------------------------------------
for my $a ( 0..$#entries ) {
$entries[$a] =~ s/^\s+//g;
$entries[$a] =~ s/\s+$//g;
chomp $entries[$a];
if ( $entries[$a] ne "" ) {
push( @clist, $entries[$a] );
}
}
# Parses out the names and command from the entries
#----------------------------------------------------------
for my $a ( 0..$#clist ) {
if ( $clist[$a] =~ /\- /i ) {
$a++;
while ( $clist[$a] !~ /\<\/item\>/i ) {
if ( $clist[$a] =~ /\/i ) {
$clist[$a] =~ s/<(.*?)>//gi;
push( @names, $clist[$a] );
$a++;
} elsif ( $clist[$a] =~ /\/i ) {
$clist[$a] =~ s/<(.*?)>//gi;
push( @commands, $clist[$a] );
$a++;
}
}
}
}
# Creates the buttons for the commands
#----------------------------------------------------------
for my $a ( 0..$#names ) {
$button = Gtk2::Button->new_with_label( $names[$a] );
$button->signal_connect( 'clicked' => sub
{
system( "$commands[$a] &" );
sleep 1;
Gtk2->main_quit();
}, $button );
$launch_vbox->pack_start( $button, $false, $false, 0 );
$button->show();
}
my $close_button = Gtk2::Button->new();
$close_button->signal_connect( 'clicked' => sub{ Gtk2->main_quit(); }, $close_button );
my $close_label = Gtk2::Label->new( "Close" );
my $ccolor = Gtk2::Gdk::Color->parse( 'red' );
$close_label->modify_fg( 'normal', $ccolor );
$close_label->show();
$close_button->add( $close_label);
$launch_vbox->pack_start( $close_button, $false, $false, 0 );
$close_button->show();
$main_window->show();
Gtk2->main;
Gtk2->main_iteration while ( Gtk2->events_pending );
exit(0);