Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
"be consistent"
 
PerlMonks  

GNOME Random Wallpaper Picker

by alexbio (Monk)
on Jun 29, 2010 at 19:15 UTC ( #847188=CUFP: print w/ replies, xml ) Need Help??

Hi monks. I've written this simple script that parses the ~/.gnome2/backgrounds.xml file, picks a random wallpaper and sets it as default using the GConf interface (obviously only for the GNOME desktop environment).

Update: corrected off-by-one error thank to jwkrahn.

#!/usr/bin/perl # Gnome random wallpaper picker. # # Copyright (C) 2010 Alessandro Ghedini <al3xbio@gmail.com> # -------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # Alessandro Ghedini wrote this file. As long as you retain this # notice you can do whatever you want with this stuff. If we # meet some day, and you think this stuff is worth it, you can # buy me a beer in return. # -------------------------------------------------------------- use Gnome2::GConf; use XML::Simple; use strict; use warnings; my $client = Gnome2::GConf::Client -> get_default; my $bg_file = $ENV{'HOME'}.'/.gnome2/backgrounds.xml'; my $key = '/desktop/gnome/background/picture_filename'; open BG, $bg_file or die $!; my $xml_data = join '', <BG>; close BG; my $xml = XMLin($xml_data); my @wallpapers; while (my ($key, $value) = each(%{$xml -> {'wallpaper'}})){ push @wallpapers, $key if $value -> {'deleted'} eq 'false'; } my $name = $wallpapers[rand(@wallpapers)]; my $selected = $xml -> {'wallpaper'} -> {$name}; print "Selected Wallpaper: $name\n"; $client -> set($key, {type => 'string', value => $selected -> {'filename'}}); __END__ =head1 NAME gnome-random-wallpaper.pl - Gnome random wallpaper picker. =head1 USAGE gnome-random-wallpaper.pl =head1 DESCRIPTION This script simply reads the ~/.gnome2/backgrounds.xml file, where are stored the default wallpapers for Gnome, randomly selects one of them, and sets it using the GConf interface. =cut

The usage is very simple, just run it without any arguments.

Alex's Log - http://alexlog.co.cc

Comment on GNOME Random Wallpaper Picker
Select or Download Code
Re: GNOME Random Wallpaper Picker
by jwkrahn (Monsignor) on Jun 29, 2010 at 20:31 UTC

    You have an off-by-one error.

    my $name = $wallpapers[rand($#wallpapers)];

    Should be:

    my $name = $wallpapers[rand(@wallpapers)];

      Thank you, I've corrected the code.

      Alex's Log - http://alexlog.co.cc
Re: GNOME Random Wallpaper Picker
by ambrus (Abbot) on Jul 04, 2010 at 15:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://847188]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-04-20 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls