Desktop Backgrounds w/ Flickr

by Calvin on August 15, 2006

I usually get my backgrounds from a couple of photo blogs I subscribe to, but using Flickr for my backgrounds was such a good idea (and a good excuse to play with ruby), that I thought I’d give it a shot.

After some trail and error, and some help online, I was able to come up with this ruby script to do the trick. The script will pull the interesting photos for that day, and will try to find the best fit for your screen resolution. If you don’t like the current background, you can run the script again to change it. With a simple cron entry you can have fresh background at periodic intervals (I have mine set to every 2 hours).

I created the script under Ubuntu GNOME. If you want to give the script a try, you’ll have to edit the script and put in your Flickr api key and shared secret as well as your screen resolution (unless you’re runing on 1440×900). You’ll also need to have rubygems and the rflickr gem installed.

{ 3 trackbacks }

tecosystems » Remember When I Asked for Flickr as a Back End to GNOME?
February 28, 2007 at 3:47 am
tecosystems » It’s the Network, Not the Application: Online Desktops
July 19, 2007 at 12:30 am
Never Tell… Richard Eibrand » Blog Archive » links for 2007-07-20
July 20, 2007 at 9:18 am

{ 10 comments… read them below or add one }

stephen o'grady August 15, 2006 at 11:54 am

you rock! can’t believe something got turned around so quickly.

only problem is that i can’t get it to work. i inserted my API_KEY and SHARED_SECRET into the file as marked, and i have both the rflickr and flickr gems installed, but it’s failing to initialize with Flickr. i’m getting the following:

ruby chg-background.rb
/usr/lib/ruby/gems/1.8/gems/flickr-1.0.0/./flickr.rb:67:in `request’: Invalid API Key (Key not found) (RuntimeError)
from /usr/lib/ruby/gems/1.8/gems/flickr-1.0.0/./flickr.rb:90:in `login’
from /usr/lib/ruby/gems/1.8/gems/flickr-1.0.0/./flickr.rb:61:in `initialize’
from chg-background.rb:25

any thoughts?

stephen o'grady August 15, 2006 at 11:55 am

should have added that the environment is Ubuntu GNOME, and ruby -v returns:

ruby 1.8.4 (2005-12-24) [i486-linux]

Calvin Yu August 15, 2006 at 12:32 pm

It looks like you have another flickr library installed. You’ll need to uninstall that one because the two different libraries conflict with each other:

gem uninstall flickr
gem install rflickr

stephen o'grady August 15, 2006 at 1:47 pm

ok, that solved part of it, but it didn’t seem to provide me with the auth URI:

ruby chg-background.rb
You must visit #{url} to authorize this application. Press enter when you have done so. This is the only time you will have to do this.

ERR: Invalid frob (108)
/usr/lib/ruby/1.8/xmlrpc/client.rb:414:in `call’: Invalid frob (XMLRPC::FaultException)
from /usr/lib/ruby/gems/1.8/gems/rflickr-2006.02.01/lib/flickr/base.rb:153:in `call_unauth_method’
from /usr/lib/ruby/gems/1.8/gems/rflickr-2006.02.01/lib/flickr/auth.rb:52:in `getToken’
from chg-background.rb:32

am i missing something obvious?

Calvin Yu August 15, 2006 at 2:04 pm

No, I didn’t check that part. I’ve uploaded an updated script. Get that, and the first time you run it you should be shown a URL that you click to authorize the app to connect to Flickr.

I also made a change to the script to not store the auth cache file in the temp directory – this way you won’t have to re-auth when the /tmp directory is cleared out.

stephen o'grady August 15, 2006 at 2:21 pm

excellent – that worked initially. only problem was that on second run, i get this:

ruby chg-background2.rb
chg-background2.rb:72: undefined method `remove’ for File:Class (NoMethodError)

Calvin Yu August 15, 2006 at 3:53 pm

Weird – at least you’re getting closer :)

All you have to do is change the word ‘remove’ to ‘delete’ to get it to work a second time (it’s strange that remove works for me).

I just updated the script again, adding that remove change as well as some other optimizations (if it works it should cycle through more images and find new images a little faster).

Neil October 30, 2006 at 2:11 pm

Thanks for the great script. Works perfectly.

Brad Wilson November 28, 2006 at 11:36 pm

Oh that’s nice man. I’ll check it out later on tonight.

Did you have any trouble using cron to call the reload desktop command? I seem to remember when I was playing with my python script that I couldn’t get cron to work. I guessed that was because it wasn’t running on the xhost or something but never got it fixed. Any ideas?

Calvin Yu November 29, 2006 at 6:56 am

Nope, the cron setup worked for me without a hitch.

Leave a Comment