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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: GNOME Random Wallpaper Picker
by jwkrahn (Abbot) on Jun 29, 2010 at 20:31 UTC | |
by alexbio (Monk) on Jun 30, 2010 at 09:10 UTC | |
|
Re: GNOME Random Wallpaper Picker
by ambrus (Abbot) on Jul 04, 2010 at 15:22 UTC |