1 #!/usr/bin/perl -wT
 2 # drop-in replacement for notify-send
 3 # it sends the notification to a remote host by marshalling the message
 4 # place it in /usr/local/bin/ for example
 5 use strict;
 6 use Getopt::Long;
 7 
 8 sub escape(\$)
 9 {
10   my $s = shift;
11   ${$s} =~ s/\n/\\n/g;
12   return $s;
13 }
14 
15 my ($category, $summary, $icon, $timeout, $message, $urgency);
16 
17 $summary = shift || "";
18 $message = shift || "";
19 
20 my $result = GetOptions ("urgency=s" => \$urgency,
21   "u=s"           => \$urgency,
22   "expire-time=i" => \$timeout,
23   "t=i"           => \$timeout,
24   "category=s"    => \$category,
25   "c=s"           => \$category,
26   "icon=s"        => \$icon,
27   "i=s"           => \$icon);
28 
29 exit unless $result;
30 
31 escape($message);
32 escape($summary);
33 
34 # collect the whole output in one variable since stderr seems to be
35 # line-buffered
36 my $lines = "";
37 $lines .= "CATEGORY $category\n" if $category;
38 $lines .= "SUBJECT $summary\n" if $summary;
39 $lines .= "URGENCY $urgency\n" if $urgency;
40 $lines .= "ICON $icon\n" if $icon;
41 $lines .= "TIMEOUT $timeout\n" if defined $timeout;
42 $lines .= "CONTENT $message\n" if $message;
43 
44 print STDERR "\033[5i";
45 print STDERR $lines;
46 print STDERR "\033[4i";