Set BING Background as your Desktop Wallpaper in GNOME

BING, GNOME, GRUB, Linux, Ubuntu, Wallpaper, bash July 18th, 2009

BING comes up with a beautiful background everyday. I thought why not set this background as my desktop wallpaper. But it would be a cumbersome task to set it manually. So I searched (Googled, BINGed) for some script which will do this for me. I found BING Downloader which does this task on Windows. I could not find any such script for GNOME. So, I thought of writing one.

I wrote a script which when executed automatically sets the GNOME wallpaper as BING background of the day. This is a PHP script. To execute this script you need to have php installed on your system. You can install php in Ubuntu as

sudo apt-get install php5 php5-cli

Now you are all set to download this script. Download Link: http://www.spsneo.com/scripts/bing_wallpaper.tar.gz

Download this file, extract the script file. Now you can run the script from terminal :
php bing_wallpaper.php

And your wallpaper is set. You can run this script daily from your terminal or you can set a cron job for the same or you can set up an icon in your gnome panel for this script.

I will keep updating this script. And I am also planning to write the same script in python. So check back again if you dont want to install php on your system.

Send your feedbacks and suggestions.

Update 1: I have modified the script to work with http proxy. Just assure that the environment variable http_proxy is properly set.

Update 2: Modified the script to keep the image centered on the desktop with black background. Try it out.

Random Wallpapers in Gnome

GNOME, Linux August 9th, 2008

There are many softwares in Windows(TM) which changes the wallpaper randomly from a given set of images. I was thinking of this for my Linux machine. I came up with a shell script. Though there can be many other ways. I just wanted to share my script and nothing else.

Update: There’s a tool which does all this automatically. drapes in Universe repository

Here in this code I am assuming that you have got all your wallpaper images in the directory /home/username/Pictures . You have to replace this directory with your wallpaper directory.

Here goes the code :

#! /bin/bash
wallpaper_folder=/home/username/Pictures
wallpaper_array=($wallpaper_folder/*.jpg)
number=${#wallpaper_array[*]}
((number=RANDOM%number))
random_wallpaper=${wallpaper_array[$number]}
gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$random_wallpaper"

Well, so let us quickly analyze the code. First line is the famous ’sha-bang’.

In the second line I am just setting the path of the wallpaper folder to the variable wallpaper_folder.

Third line I am creating an array containing all the file names with the extension jpg in the directory ‘wallpaper_folder’ (spaces are being escaped). More about bash arrays here.

Fourth line, I am calculating the number of elements in the array. This is the standard method of calculating the number of elements in a bash array. (replacing # with @ will also work fine).

Then in the fifth line, random number is generated within the range 0 to ‘number’. More about random numbers in bash here.

Sixth line set the variable random_wallpaper to the value corresponding to the key ‘number’ in the array wallpaper_array.

Seventh line, finally sets the file ‘random_wallpaper’ as the wallpaper. gconftool-2 is used to do customization in GNOME settings. Check out the man pages of gconftool-2 to know more about it. There’s a GUI tool for this gconftool-2 : gconf-editor

Now this script just sets the wallpaper randomly from a given set of images. Now you can schedule this script using cron to execute it at some regular interval. (In case you dont know what is cron, check out the manual pages of cron and crontab).