Skip to content

Instantly share code, notes, and snippets.

@mjdominus
Created November 22, 2011 20:11
Show Gist options
  • Save mjdominus/1386774 to your computer and use it in GitHub Desktop.
Save mjdominus/1386774 to your computer and use it in GitHub Desktop.
Timed alert program
#!/icg/bin/perl
use Getopt::Std;
my %opt;
getopts('t:', \%opt);
my $z = shift or die;
if ($z =~ s/m$//) { $z *= 60 }
elsif ($z =~ s/h$//) { $z *= 3600 }
elsif ($z =~ s/s$//) { $z *= 1 }
elsif ($z =~ /\D/) { die "Usage: timer [ 30[s] | 5m | 1h ] message...\n" }
my $timeout = $opt{t} * 1000 || int($z * 33.333);
$timeout = 1000 if $timeout < 1000;
@ARGV = ('Timer expired') unless @ARGV;
exit if fork();
sleep $z;
exec "notify-send", "-t", $timeout, @ARGV;
die "exec notify-send: $!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment