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