2 ###APPNAME: r-wallpapers-daemon
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Tue Mar 25 21:36:40 2008
6 ###APPDESC: set wallpaper randomly,timely
7 ###APPUSAGE: [seconds] [directories...]
13 exit(system("plhelp",$0,@ARGV)) if($_ eq "-h" || $_ eq "--help");
16 my $CONFIG_D = "$HOME/.xiaoranzzz";
17 unless(-d
$CONFIG_D) {mkdir $CONFIG_D or die("$!\n");};
18 unless(-d
$CONFIG_D) {mkdir $CONFIG_D or die("$!\n");};
19 my $WP_LIST = "$CONFIG_D/wallpapers";
20 #my $WP_LAST = "$CONFIG_D/last-wallpaper";
22 $wait=300 unless($wait);
26 print STDERR
"Building wallpaper list...";
30 open FI
,"-|","find '$_' -name '*.png' -or -name '*.jpg'";
31 foreach my $png(<FI
>) {
39 print STDERR
" [Done]\n";
42 print STDERR
"Reading wallpaper list...";
55 print STDERR
"No wallpaper found, the list is empty\n";
62 # print STDERR "$0 quiting ...\n";
63 # print STDERR "Save $WPS[$nextid] as last wallpaper\n";
64 # open FO,">",$WP_LAST;
65 # print FO $WPS[$nextid],"\n";
67 # print STDERR "$0 quit\n";
74 print STDERR
"\n$0 quit\n";
82 $SIG{USR1
}=\
&do_change
;
85 $nextid=int(rand(@WPS));
86 my @app = ($nextid % 9) ? qw
/set_wallpaper/ : qw
/set_wallpaper 1/;
87 if( -f
$WPS[$nextid] ) {
88 print STDERR
"\nSetting wallpaper to $WPS[$nextid] ...";
89 if(system(@app,$WPS[$nextid])==0) {
90 print STDERR
"\rSetting wallpaper to $WPS[$nextid] ... [Done]";
93 print STDERR
"\rSetting wallpaper to $WPS[$nextid] ... [Failed]";
96 if($action eq "change") {
99 elsif($action eq "exit") {
105 $action="" if($action eq "change");