in reply to Re^3: how to loop
in thread how to loop
#!/usr/bin/perl use strict; use warnings; use XML::Simple; srand; # Mode to run my $mode = "startup"; # Interval to change at if we want $mode = "running" my $interval = $ARGV[0]; # Change the mode if we have been passed an interval $mode = "running" if ($interval); # 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"; # Die if we dont have a background xml file die("No backgrounds file [$xmlfile] found!") if (! -e $xmlfile); # 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 while (1) { # 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 . + '\''); # Break out of our while loop if mode ne "running" last if ($mode ne "running"); # Sleep for some time sleep($interval*60); } # end-while exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: how to loop
by graff (Chancellor) on Feb 21, 2007 at 08:13 UTC |