rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
loop: # Get a random background from the array my $new = $backs[int(rand(@backs))]; # Set the background to something new system($command . ' --type=string -s '. $gconf_item . ' \'' . $new . ' +\''); if ($mode eq "running") { sleep($interval*60); goto("loop"); } # end-if
#!/usr/bin/perl use strict; use warnings; use XML::Simple; srand; # Mode to run #my $mode = "startup"; my $mode = "running"; # Interval to change at if $mode eq "running" my $interval = 60; # gconf vars my $command = "gconftool-2"; my $gconf_item = "/desktop/gnome/background/picture_filename"; # The location of the background xml file my $xmlfile = $ENV{HOME} . "/.gnome2/backgrounds.xml"; # Find the current background so we dont change to this my $current = `$command -g $gconf_item`; # Read in the xml file contents to get our list of backgrounds my $config = XMLin($xmlfile); # Something to store our filenames in my @backs; foreach my $name (keys %{$config->{wallpaper}}) { # Skip any that have a deleted flag in the XML file next if ($config->{wallpaper}->{$name}->{deleted} eq "true"); # Set the filename my $file = $config->{wallpaper}->{$name}->{filename}; # Ignore the current background and the (none) background next if (($file eq $current) || ($file eq "(none)")); # Store the name in our array push(@backs, $file); } # end-foreach loop: # Get a random background from the array my $new = $backs[int(rand(@backs))]; # Set the background to something new system($command . ' --type=string -s '. $gconf_item . ' \'' . $new . ' +\''); if ($mode eq "running") { sleep($interval*60); goto("loop"); } # end-if exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to loop
by Zaxo (Archbishop) on Feb 21, 2007 at 02:14 UTC | |
by rsiedl (Friar) on Feb 21, 2007 at 02:20 UTC | |
by cbrandtbuffalo (Deacon) on Feb 21, 2007 at 15:00 UTC | |
|
Re: how to loop
by muba (Priest) on Feb 21, 2007 at 04:37 UTC | |
by rsiedl (Friar) on Feb 21, 2007 at 05:27 UTC | |
by graff (Chancellor) on Feb 21, 2007 at 07:42 UTC | |
by rsiedl (Friar) on Feb 21, 2007 at 07:57 UTC | |
by graff (Chancellor) on Feb 21, 2007 at 08:13 UTC | |
|
Re: how to loop
by andye (Curate) on Feb 21, 2007 at 18:52 UTC | |
by geekphilosopher (Friar) on Feb 21, 2007 at 19:57 UTC |