Nerdettes weblog

Just another view of/by nerdette.org

Constantly changing backgrounds on your ubuntu/linux desktop


On my website I had gathered and uploaded some wallpapers I’d like to use, but never found time to setup a constantly changing background wallpaper.
Now, with help of this article and the script it’s a very quick step to get this done.
I made a directory ‘wallpaper‘ (note: root user ownership) under /usr/share/backgrounds/ and put all the jpgs in there.
Then you run the script; it will generate the xml file for you which you will need to select as ‘background’ : I put it all in /usr/share/backgrounds/wallpaper/ and the xml file I wanted was called wallpaper.xml

Then, on the main desktop; rightclick and select ‘Change Desktop Background” and hit ‘Add’. Then browse to /usr/share/backgrounds/wallpaper/ and select “All Files” at the right bottom of the screen.

I then selected the wallpaper.xml file et voila, it immediately started with displaying the first wallpaper I had downloaded to that directory :)

More information as well as screenshots via
http://www.linuxjournal.com/

All credits go to David J. Kranjnik for the script – saved my day ;)


#!/bin/sh
#This script creates xml files that can act as dynamic wallpapers for Gnome by referring to multiple wallpapers
#Coded by David J Krajnik

if [ "$*" = "" ]; then
echo "This script creates xml files that can act as dynamic backgrounds for Gnome by referring to multiple wallpapers";
echo "Usage: mkwlppr.sh target-file.xml [duration] pic1 pic2 [pic3 .. picN]";
else
files=$*;
#Grab the name of the target xml file
xmlfile=`echo $files | cut -d " " -f 1`;
#remove the first item from $files
files=`echo $files | sed 's/^\<[^ ]*\>//'`;
if [ "`echo $xmlfile | grep '\.xml$'`" = "" ]; then
echo "Your target file must be an XML file";
else
inputIsValid="true";
firstItem=`echo $files | cut -d " " -f 1`;
duration="1795.0";#set the default duration
if [ "`echo $firstItem | grep '^[0-9]\+\.[0-9]\+$'`" != "" ]; then
echo "The duration must be an integer";
files=`echo $files | sed 's/^\<[^ ]*\>//'`;
inputIsValid="";
elif [ "`echo $firstItem | grep '^[0-9]\+$'`" != "" ]; then
#If the item is a number, then use it as the duration for each wallpaper image
duration="`expr $firstItem - 5`.0";
#remove the duration from the list of files
files=`echo $files | sed 's/^\<[^ ]*\>//'`;
fi
if [ "$files" = "" ]; then
echo "You must enter image files to associate with the XML file";
else
for file in $files
do
if [ ! -f $file ]; then
echo "\"$file\" does not exist";
inputIsValid="";
elif [ "`echo $file | sed 's/^.*\.\(jpg\|jpeg\|bmp\|png\|gif\|tif\|tiff\|jif\|jfif\|jp2\|jpx\|j2k\|j2c\)$//'`" != "" ]; then
echo "\"$file\" is not an image file";
inputIsValid="";
fi
done
if [ $inputIsValid ]; then
currDir=`pwd`;
echo "" >> $xmlfile
echo " \n 2009\n 08\n 04" >> $xmlfile;
echo " 00\n 00\n 00\n
" >> $xmlfile;
echo " " >> $xmlfile;
firstFile=`echo $files | cut -d " " -f 1`;#grab the first item
if [ "`echo $firstFile | sed 's/\(.\).*/\1/'`" != "/" ]; then
#If the first character in the filename is not '/', then it is a relative path and must have the current directory's path appended
firstFile="$currDir/$firstFile";
fi
firstFile=`echo $firstFile | sed 's/[^/]\+\/\.\.\/\?//g'`;#Remove occurrences of ".." from the filepath
files=`echo $files | sed 's/^\<[^ ]*\>//'`;#remove the first item
prevFile=$firstFile;
currFile="";
#TODO add absolute path to the filenames
#if $currFile =~ "^/.*" then the file needs to path appended
echo " \n $duration\n $firstFile\n " >> $xmlfile;
for currFile in $files
do
if [ "`echo $currFile | sed 's/\(.\).*/\1/'`" != "/" ]; then
#If the first character in the filename is not '/', then it is a relative path and must have the current directory's path appended
currFile="$currDir/$currFile";
fi
currFile=`echo $currFile | sed 's/[^/]\+\/\.\.\/\?//g'`;#Remove occurrences of ".." from the filepath
echo " \n 5.0\n $prevFile\n $currFile\n " >> $xmlfile;
echo " \n $duration\n $currFile\n " >> $xmlfile;
prevFile=$currFile;
done
echo " \n 5.0\n $currFile\n $firstFile\n " >> $xmlfile;
echo "
" >> $xmlfile;
fi
fi
fi
fi

Share:

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.