Created
November 22, 2011 20:11
-
-
Save mjdominus/1386774 to your computer and use it in GitHub Desktop.
Timed alert program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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