Thursday, April 1, 2010

Change the desktop background using Perl script - GNOME (Fedora and Ubuntu)

Hi Guys,

These days people are opting Linux distributions like Fedora, Ubuntu, etc., for their PC's mainly to avoid malware and virus attacks. Bundling them with all kind of multimedia and entertainment tools make them more interesting and the fact that they are free make them further irresistible.

Many of the home users find them wanting. But there are small things that you would find irritating, say, something as simple as changing the desktop background. To make your life simple, here I have made a simple, sample perl script to change the desktop image. It will download pictures from National Geographic website and set it as your wallpaper. This is just a sample script, if you have the time please try it out with different website/urls. I am sure, you might as well start learning perl like I did... :-)

Note : If you want to run this script daily, just add an entry in the crontab. Crontab entry must be Xserver login user and not other users.

Here the script:-
-----------------

#!/usr/bin/perl

use WWW::Mechanize;

my $url  = "http://photography.nationalgeographic.com/photography/photo-of-the-day/";

my $mech  = WWW::Mechanize->new();
$mech->get( $url );
my @links = $mech->links();
my $download_link;

foreach my $link (@links)
{
   if  ($link->text() eq "Download Wallpaper (1600 x 1200 pixels)")
      {
       $download_link = $link->url();
       last;
      }
}

$uri = $download_link;
$date_time = localtime(time);
my @file_name = split(' ',$date_time);

#Picture will be stored in "/home/vivek/Pictures/" folder and file will be like this "Apr-1-2010.jpg"
#Change the path/folder...
 
$tempfile = "/home/vivek/Pictures/$file_name[1]-$file_name[2]-$file_name[4].jpg";

$mech->get( $uri, ':content_file' => $tempfile );


if ( -e $tempfile )
{
system("gconftool-2 --type string --set /desktop/gnome/background/picture_filename $tempfile");
}

-------------------

Important links:-

http://photography.nationalgeographic.com/photography/photo-of-the-day/
http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize.pm

19 comments:

Andy Lester said...

You don't have to search through the links yourself. Do this:

$download_link = $mech->find_link( text => 'Download Wallpaper (1600 x 1200 pixels)' );

vendull said...

I took this idea a bit further and added resizing to make the image tile evenly across multiple displays (sigh.. I wish gnome wasn't so brain dead in this regard):

http://github.com/mschout/ng-daily-wallpaper/blob/master/bin/ng-daily-wallpaper

Vivek said...

Hi Andy & Vendull,

Thanks for your comments.

I am sure, my next post will be a improved one.


Regards,
Vivek

Anonymous said...

Hi,

We are new company which offer SEO services. For all customer who contact us in 5 day we will made a special offer.
If you sign agreement for 12 months we don't charge you within first 6 month.
Be first and visit our site and ask us about special offer for you.

SEO/SEM [url=http://www.budownictwo-swiatowe.nowa-architektura.com.pl/]Buildings Site[/url]

Masage for forum moderator: Please don't delete this massage and contact us. We have special offer for you.
We can increase traffic of your forum for free (only if you will not cancel this massage).

Best Regards
SEO/SEM Manager
Adam Tolman
[url=http://www.miejsca.wyprawyturystyczne.info.pl/]Nice place[/url]

generic cialis 20mg said...

Hello, I do not agree with the previous commentator - not so simple

extreme bondage sex said...

Great website, looks very clean and organized. And very interesting to read Your the article!

lesbian bondage videos said...

Great website, looks very clean and organized.

Anonymous said...

Message74, http://www.arlo.net/massacree/ viagra online in uk, scen8, http://www.arlo.net/fccgb/ viagra no prescriptions, rjqr2, http://www.arlo.net/fccgb/notes/ generic viagra online, jfke0, http://www.arlo.net/bytes/ cheap viagra, xiod3, http://www.arlo.net/live/ viagra sale

Anonymous said...

pczh [url=http://www.bootssay.com]http://www.bootssay.com[/url]
Therefore I was very inquiring once i read that Thierry Costes, the intelligent younger restaurateur who's built this sort of warranted results of the Motel Amour inside the 5th, had taken more than this aged warhorse in cohesiveness with Jean-Francois Piege, the fantastic fresh cook at Des Ambassadeurs for the Hotel environnant les Crillon. Maybe finally someone would attempt to significantly resurgence the brasserie with the twenty-first century, to generate a trendy spot past the old Costes friends idiom of rather but snippy waitresses, lifeless basic foodstuff for individuals that do not really care about foodstuff, plus a bar music soundtrack and decoration?


dlgy [url=http://www.bootssay.com]Cheap Ugg Boots[/url]
That is all great news with the Uggs company which we have arrived at know and enjoy. Federal government subsidy applications (specifically in Germany and Asia) and natural pricing guidelines of utility bills or electric power providers have sti . Heckler and Koch pistols are selected service pistols for the police pushes in Germany and United States Of America, an . And delicious muffins are an important part of this. It's really a colour standing for royal and elegant. In previous times, it does not take royal's exceptional color. In vogue industry, it may be a different favorite from the manufacturers now. To brides to be, gold we . There sq determine numerous models factory-manufactured by Nikon that happen to be nice by its consumers. Nikon D5100 is such mo .


lqiq [url=http://www.bootswould.com]www.bootswould.com[/url]
Some shoes or boots give a 3 inch placed, buckskin-covered midsole inside a iron wedge. Blockages are an additional obtain alternative with 4 " largemouth bass wooden outsoles and rubberized traction within the lows. Ugg boot is found with links, rivets or nail-scalp accents. Ribbons-up boot styles tend to be created for extreme weather conditions and gratifaction, with watertight buckskin uppers and excellent traction.

Anonymous said...

websites for queer dating http://loveepicentre.com/taketour.php free dating nudes

Anonymous said...

learn real estate ebook http://audiobookscollection.co.uk/fr/On-the-Move-to-Meaningful-Internet-Systems-2005-OTM-2005-Workshops-OTM-Confederated-International-Workshops-and-Posters-AWeSOMe-CAMS-GADA-Applications-incl-Internet-Web-and-HCI/p209557/ dr daniel amen ebook torrents [url=http://audiobookscollection.co.uk/Daisy-Miller/p228142/]ebook of fashion design[/url] free hamlet ebook

Anonymous said...

terry goodkind soul on fire ebook http://audiobooksplanet.co.uk/Gouxiong-Xue/m44929/ online ebooks ebook bargains [url=http://audiobooksplanet.co.uk/it/Dello-sport/c1070/?page=5]at home in old sodus ebook[/url] ebook flashpaper

Anonymous said...

ebook open sourceware http://audiobooksworld.co.uk/it/authors/?letter=E&page=4 specter of the past ebook [url=http://audiobooksworld.co.uk/es/Production-Safety-for-Film-Television-and-Video/p211844/]ebook kindle reviews[/url] free win over words ebook

Anonymous said...

acrobat writer 7 pdf software windows http://buyoem.co.uk/es/category-200-206/Programas-del-servidor panda software worldwide list [url=http://buyoem.co.uk/fr/product-18339/DRM-Dumpster-Disk-Mac]medilog software development[/url] sheltered workshop payroll software
[url=http://buyoem.co.uk/es/product-37391/Easy-MPEG-AVI-DIVX-WMV-RM-to-DVD-1-6]Easy MPEG AVI DIVX WMV RM to DVD 1.6 - Cheap Legal OEM Software, Software Sale, Download OEM[/url] task reminder software
[url=http://buyoem.co.uk/product-11146/XPTools-Software-WinUtilities-5-3][img]http://buyoem.co.uk/image/8.gif[/img][/url]

Anonymous said...

mbp software http://buyoemsoftware.co.uk/product-37345/Ultra-Video-Converter-4-4 government approved security overwriting software [url=http://buyoemsoftware.co.uk/product-26849/Intellexer-Summarizer-Pro-3-0]best pc antivirus software[/url] pacemaker monitoring software
[url=http://buyoemsoftware.co.uk/product-37222/Nicos-Commander-5-6]Nicos Commander 5.6 - Software Store[/url] memory sticky recovery software
[url=http://buyoemsoftware.co.uk/de/category-100-101/Betriebssysteme?page=2][img]http://buyoem.co.uk/image/4.gif[/img][/url]

Anonymous said...

golden software surfer http://buysoftwareonline.co.uk/de/product-35553/Picturesque-2-0-MacOSX best video edit software [url=http://buysoftwareonline.co.uk/product-36997/ACD-Canvas-12-Wine]tallys pipe yard software[/url] good internet security software
[url=http://buysoftwareonline.co.uk/es/product-10452/Microsoft-Office-Enterprise-2007]Microsoft Office Enterprise 2007 - Cheap Legal OEM Software, Software Sale, Download OEM[/url] measured cost of software attacks
[url=http://buysoftwareonline.co.uk/it/product-37182/Watermark-Master-1-2][img]http://buyoem.co.uk/image/1.gif[/img][/url]

Anonymous said...

Replica HermesBirkin Bags zuhz Hermes BeltsHermes Belts jiwg

Anonymous said...

[url=http://englandpharmacy.co.uk/products/tegretol.htm][img]http://onlinemedistore.com/9.jpg[/img][/url]
cvs pharmacy alachua http://englandpharmacy.co.uk/products/tadacip.htm pharmacy omeprazole [url=http://englandpharmacy.co.uk/products/aldactone.htm]pharmacy glossary[/url]
pharmacy school jacksonville fl http://englandpharmacy.co.uk/products/tricor.htm pharmacy tech certificat [url=http://englandpharmacy.co.uk/products/atrovent.htm]atrovent[/url]
what does the hierarchy for a pharmacy technician look like http://englandpharmacy.co.uk/products/flagyl-er.htm national pharmacy technician certification exam [url=http://englandpharmacy.co.uk/products/serophene.htm]navy pharmacy scholarship[/url]
pharmacy benefit management audit http://englandpharmacy.co.uk/products/flomax.htm hi school pharmacy in sandy oregon [url=http://englandpharmacy.co.uk/products/requip.htm]requip[/url]

Anonymous said...

black men dating white women http://loveepicentre.com/articles/ islamic dating sites
who is monica dating [url=http://loveepicentre.com/taketour/]dating game icp mp3[/url] chat dating free web cam
white collar dating service [url=http://loveepicentre.com]birer dating[/url] free divorced dating sites [url=http://loveepicentre.com/user/Tasha/]Tasha[/url] gabrielle union and ludacris dating