Fresh Backgrounds
Rotating backgrounds in Ubuntu 11
I don’t know about you, but I love change. One of the simplest ways to accomplish this is having fresh, inspiring images on your desktop. It would drive me crazy if I had to walk into to the office every morning and stare at the exact same display I always did. Or if I awoke from the same dream, from the same bed at the same time, looked in the same mirror, made the same frown, and felt the same way as I did everyday (blur lyrics if anyone hasn’t caught on yet).
Rotating the directory, automatically
Ubuntu has the ability to create wallpaper slideshows, which helps alleviate this issue, but unfortunately, creating these slideshows is a pain in the ass. I ended up writing a quick python script that will do this automatically. It simply transitions between every file in a directory you specify. Just go to InterfaceLift and start downloading.
To configure: simply replace backgrounds_dir and xml_file from the following:
#!/usr/bin/python import os,random backgrounds_dir = '/home/wes/Pictures/backgrounds' xml_file = '/usr/share/backgrounds/contest/background-1.xml' duration = 10 * 60 transition_duration = 10 def begin(): return '<background><starttime><year>2009</year><month>09</month><day>06</day><hour>00</hour><minute>00</minute><second>00</second></starttime>' def end(): return '</background>' def create_entry(current_bg, next_bg): text = '<static><duration>' + str(duration) + '</duration><file>' + current_bg + '</file></static>' text += '<transition><duration>' + str(transition_duration) + '</duration><from>' + current_bg + '</from><to>' + next_bg + '</to></transition>' return text if __name__ == "__main__": background_xml = begin() background_list = [] for filename in os.listdir(backgrounds_dir): background_list.append(backgrounds_dir + '/' + filename) random.shuffle(background_list) x = 0 while x < len(background_list): if x == len(background_list) - 1: next = 0 else: next = x+1 background_xml += create_entry(background_list[x], background_list[next]) x += 1 background_xml += end() f = open(xml_file, 'w') f.write(background_xml)
To make the change, just run the script. Or if you constantly add images to your backgrounds folder, add the script to your crontab:
0 */8 * * * /home/wes/scripts/background_change.py
Enjoy, and stop being so boring.




