Skip to content

Instantly share code, notes, and snippets.

@edipretoro
Created February 26, 2010 22:15
Show Gist options
  • Save edipretoro/316238 to your computer and use it in GitHub Desktop.
Save edipretoro/316238 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Desktop::Notify;
use IPC::Run qw( run );
use Getopt::Long;
use Sys::Hostname;
my $config = {
message => 'Succeed!',
fail => 'FAILED',
title => hostname(),
};
Getopt::Long::Configure('pass_through');
GetOptions( $config, 'message=s', 'fail=s', 'title=s' );
if ( scalar(@ARGV) == 0 ) {
die "$0: must provide a command to execute\n";
}
else {
my $notify = Desktop::Notify->new();
my $notification;
eval { run \@ARGV };
my $exitcode = $? >> 8;
if ( $exitcode == 0 ) {
$notification = $notify->create(
summary => $config->{title},
body => $config->{message},
timeout => 5000,
);
}
else {
$notification = $notify->create(
summary => $config->{title},
body => $config->{fail},
timeout => 5000,
);
}
$notification->show();
$notification->close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment