Valkertown Blog

I used to write about electronics…

Valkertown Blog header image 2

Setting my desktop backgrounds from Flickr

December 2nd, 2008 by Carlos Perilla

Well I’m now trying to publish here some of the tools I use and write everyday to customize my desktop, most of them are simple hacks, this time it’s a way to set your desktop background from a Flickr feed that is requested to be filtered using some tags.

Heres the code:

  1. #!/usr/bin/python
  2.  
  3. import feedparser
  4. import urllib
  5. import random
  6. FLCKR_API = "http://api.flickr.com/services/feeds/photos_public.gne"
  7. TAGS = "fantasy,nature,night,dog,art,beach"
  8.  
  9. query = urllib.urlencode(((‘tags’,TAGS),(‘tagmode’,‘any’)))
  10. entries = feedparser.parse("%s?%s" % (FLCKR_API,query))
  11. links = []
  12. for entry in entries[‘entries’]:
  13.     for href in  entry[‘links’]:
  14.         if "image" in href[‘type’]:
  15.             links.append(href[‘href’])
  16.  
  17. print random.choice(links)
  18.  

You should set TAGS=”" to the tags you want to filter the backgrounds.

Now to use it I have the following script that I tried to make smart enough to notice when I have a dual head setup and grabs two images and makes a composition so I will have a different background on each monitor, it works nice but it has its problems.

  1. #!/bin/sh
  2.  
  3. TOT=`wc -l ~/New.list | cut -f1 -d" "`
  4. if [ -f /tmp/flickr ]; then
  5.     wget `flickrget` -O /tmp/bg1.jpg > /dev/null 2>&1
  6.     BG1="/tmp/bg1.jpg"
  7. else
  8.     BG1=`sed -n $[RANDOM % TOT]p ~/New.list`
  9. fi
  10. DIMENSIONS=`xdpyinfo | grep dimensions | sed s/".* \([0-9]*x[0-9]*\) pixels.*"/"\1"/`
  11.  
  12. if [ "$DIMENSIONS" == "1440×900" ]; then
  13.     Esetroot -f $BG1
  14. else
  15.     if [ -f /tmp/flickr ]; then
  16.         wget `flickrget` -O /tmp/bg2.jpg > /dev/null 2>&1
  17.         BG2="/tmp/bg2.jpg"
  18.     else
  19.         BG2=`sed -n $[RANDOM % TOT]p ~/New.list`
  20.     fi
  21.     nice -20 montage -background black  -geometry 1440×900 $BG1 $BG2 /tmp/cur_bg.bmp
  22.  
  23.     Esetroot -c /tmp/cur_bg.bmp
  24. fi
  25.  

There are several things on the previous scripts that should be tweaked, first ~/New.list it’s a list of my local list of backgrounds, 1440×900 it’s my laptop internal video size, /tmp/flickr it’s a file I use to control the source of my desktop backgrounds and finally flickrget its the name I choose for the previous python script and set it on my path.

I have setup the shell script on my awesome client to be run every 30 minutes so I get a new background after that time but also a button on my status bar to force a change when I don’t like the background it choose for me.

EOP

Tags:   · · · · · · · Comments

  • Joseph Gay
    I know this is old, but, strangely enough, I did almost the exact same thing in stumpwm before seeing this, even down to the 30 minute time interval for retrieving new backgrounds and the tag list for performing searches, although mine pulls from a group and uses a text instead of tag based search. I was actually looking for a way to handle multi-head setups when I stumbled across this page. Great minds think alike, right?
  • Sure let me google a bit about it.

    It seems that for ubuntu the simplest way would be something like this:


    gconftool-2 --type string --set /desktop/gnome/background/picture_filename "/path/to/image.ext"

    So in the script it would be replace line 13 with

    gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$BG1"

    and line 23 with

    gconftool-2 --type string --set /desktop/gnome/background/picture_filename /tmp/cur_bg.bmp

    Try it and tell me if it works
  • Can you think of any possible alternative to installing Eterm?
  • Well you can install Eterm it most likely will install also Esetroot.

    I use it since it works with the transparency from rxvt-unicode but you could replace it with some other command that lets you set the background from the command line.

    There was a little mistake that now is corrected on the post, on line 9 of the python script it should be "tagmode" and not "tagsmode", otherwise you will end with a very narrow set of images.
  • Hmm, this looks really cool. However, I'm getting an error when I try this script.

    crashsystems@crashsystems-laptop:~$ ./changebg.sh
    ./changebg.sh: line 46: Esetroot: command not found

    I'm running Ubuntu 8.10
blog comments powered by Disqus