geowall-NGC's photo of the day as Ubuntu wallpaper
15 February 2014

Why ?

I believe automation is an integral part of technology, and scripts are a great way to automate your tasks.

What

I like my wallpaper to be dynamic, unexpected, natural and beautiful at the same time. All this come together in National Geographic Channel’s photo of the day. I knew it will be the perfect wallpaper. But to download and apply the wallpaper daily is just unethical for a coder. So I decided to write a script to do exactly that.

Research

The first thing to do was to find out where to get the NGC’s photo of the day.

A simple Google search revealed that it resides at the address http://photography.nationalgeographic.co.in/photography/photo-of-the-day/

Steps

Downloading the page

Ok, so I have the url of the page. Using this, I can get the whole page using wget and save it in a file in the /tmp folder.

wget --quiet http://photography.nationalgeographic.co.in/photography/photo-of-the-day/ -O /tmp/ngc.html

Extracting the url

After having a look at the source code, I could see a pattern and write a grep command

url=`grep -o -m 1 images.nationalgeographic.com/wpf/media-live/photos/.*x.*jpg /tmp/ngc.html`

Now the url to the image is saved in the bash variable “url”.

Downloading the photo

wget comes handy again.

wget --quiet http://$url -O /tmp/pic.jpg

Setting the wallpaper

Finally, set the downloaded wallpaper (in Ubuntu)

gsettings set org.gnome.desktop.background picture-uri file:///tmp/pic.jpg

That’s it! I encourage you to view, download and contribute to the script on Github.

Thanks for reading. Do comment!