Home > python > Set Bing images as your wallpaper

Set Bing images as your wallpaper

You like Bing background images so much that you want to see them on your desktop too. How to fetch the image of the day with a script?

I made a simple Python script for this purpose:

#!/usr/bin/env python

Download the background image of the day from BING
and set it as your Gnome desktop wallpaper.

Tested under Ubuntu GNU/Linux. This script requires
the 'jabbapylib' library, available via PyPI.

Inspired by http://spsneo.com/blog/2009/07/18/set-bing-background-as-your-desktop-wallpaper-in-gnome/ ,
where the author provides a PHP solution.

(1) Customize the SAVE_DIR variable below. Images will be stored there.
(2) Call this script once a day. The best way is to put it in the crontab.

# from jabbapylib.apps import bing

import os
from jabbapylib.web import web #@UnresolvedImport
from urlparse import urljoin
from jabbapylib.dateandtime.dateandtime import get_date_from_year_to_day
from jabbapylib.platform.gnome import gnome

URL = 'http://www.bing.com'
SAVE_DIR = '/trash/bing'

def extract():
    text = web.get_page(URL)
    text = text.split('g_img={url:')[1]
    text = text.split(',')[0].replace("'", "")
    img_url = urljoin(URL, text)
    fname = img_url.split('/')[-1]
    img_ext = os.path.splitext(fname)[1]
    save_name = get_date_from_year_to_day() + img_ext
    return (img_url, save_name)

def download(url, fname):
    dest = "{dir}/{fname}".format(dir=SAVE_DIR, fname=fname)
    cmd = "wget '{url}' -O {dest}".format(url=url, dest=dest)

    if os.path.isfile(dest):
    return dest

def main():
    img_url, save_name = extract()
    print '#', img_url
    saved = download(img_url, save_name)


if __name__ == "__main__":

The latest version is available here. The code relies on my jabbapylib library (installable with pip).

If you don’t want to install jabbapylib, this script can be turned easily into a self-contained file.

Extra stuff
The script above can set your wallpaper not only under Gnome 2 but under Gnome 3 (Unity, Gnome Shell) too. Adding this feature required some research.

Call it once a day
To get your desktop refreshed every day, call this script once a day. The easiest way is to use crontab. Example:

0 0 * * * /path/to/bing.py

Meaning: call it every day at midnight.


I was inspired by the following posts:

  1. gindc
    April 9, 2012 at 23:53

    Hey Jabba. Just wanted to say this site is great. I like your programming style. Your code here gave me some good ideas. I’ve struggled using urllib2. Using “wget” is genius. I should have been doing this for years.

    Please keep up the site and the great work.

    • April 9, 2012 at 23:57

      Thanks. You can also check out the jabbapylib.web.web module. I have lots of wrapper functions around urllib2, making downloading web content very easy.

  2. April 27, 2012 at 23:15

    Does this grab a high resolution image or is it the same size as the one on the homepage?

    • April 27, 2012 at 23:38

      Same size. If you know how to grab a high-res image, let me know.

  3. October 28, 2012 at 19:29

    Hi there,

    Was just going through your post, helpful info here. Thanks.

    For the high resolution image download, I came across a link that you might find useful. Here it is – http://totallyradadventures.blogspot.in/2012/05/bing-image-as-ubuntu-desktop-background_12.html

  4. November 26, 2012 at 17:47


    I’m using Ubuntu 12.10 and I had thought I installed all the dependancies. However, I came across this:

    Traceback (most recent call last):
    File “/home/john/Misc/scripts/bing.py”, line 25, in
    from jabbapylib.platform.gnome import gnome
    File “/usr/local/lib/python2.7/dist-packages/jabbapylib/platform/gnome/gnome.py”, line 23, in
    ver = get_gnome_session_version()
    File “/usr/local/lib/python2.7/dist-packages/jabbapylib/platform/gnome/gnome.py”, line 22, in get_gnome_session_version
    return int(version.split()[1][0]) # main version number
    ValueError: invalid literal for int() with base 10: ‘G’

    Any ideas?


    • November 26, 2012 at 19:34

      What does “gnome-session –version” return in command line?

  5. Sidharth Sudarshan
    July 7, 2013 at 14:18

    im not sure if its something in your script, ( download() being called twice? ), or if theres a particular way to call python in cron, but the above script is triggering two separate downloads from bing, both consistently 2 seconds apart. The first one succeeds but the second one tries to resolve “http://-o/” for some reason, fails, and leaves me with a blank desktop, and no new image file in my destination folder. Also, the script works perfectly stand-alone. Through crontab -e, nothing happens. The above behaviour is only displayed when i simulate it through the scheduled tasks application. help?

    • July 7, 2013 at 14:33

      My crontab looks like this:

      0 22 * * * $DIR/bing.py >>$HOME/bing.log.txt

      I hope this helps.

  6. Sidharth Sudarshan
    July 7, 2013 at 16:32

    nope, no luck. Any other ideas?

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: