Friday, June 3, 2011

Background on Ubuntu

Recently, I installed Ubuntu on my machine. I have a folder called climbingwallpapers in

/usr/share/backgrounds/

with all kinds of background pictures. Anyway, I wanted to have a bunch of desktop background that changes from time to time. I notice that there is an xml file that does this in one of the default installation folder with images.

I'm sure there is an easier way to come up with the xml file for the backgrounds in my folder.
But I didn't bother to google. Just wrote this short script....and ran it. If you would like to use it, I've attached it here. Just make the necessary changes and run it like...

$ python generatedesktoptheme.py > background-1.xml

the script is below...
#!/usr/bin/env python
import os
import re

transition = '5.0'
duration = '300'
count = 0
firstfile = ''
ffrom = ''
path = '/usr/share/backgrounds/climbingwallpaper/'

print "<background>"
print " <starttime>"
print " <year>2009</year>"
print " <month>08</month>"
print " <day>04</day>"
print " <hour>00</hour>"
print " <minute>00</minute>"
print " <second>00</second>"
print " </starttime>"
print "<!-- This animation will start at midnight. -->"

for f in os.listdir(path):
if re.search("\.jpg|\.gif", f):
count+=1
if count == 1:
firstfile = f
else:
continue

f = path+f
if ffrom == '':
ffrom = f
print " <static>"
print " <duration>"+duration+"</duration>"
print " <file>"+f+"</file>"
print " </static>"
else:
print " <transition>"
print " <duration>" +transition+"</duration>"
print " <from>"+ffrom+"</from>"
print " <to>"+f+"</to>"
print " </transition>"
ffrom = f
print " <static>"
print " <duration>"+duration+"</duration>"
print " <file>"+f+"</file>"
print " </static>"

print " <transition>"
print " <duration>"+transition+"</duration>"
print " <from>"+ffrom+"</from>"
print " <to>"+path+firstfile+"</to>"
print " </transition>"
print "</background>"