Update 2011-11-20: Now working with Ubuntu 11.10+
I’ve always been pretty jealous of my Windows 7-using friends with their fancy rotating backgrounds so I thought I’d do a bit of research into adding similar functionality into Ubuntu. After a little investigation I found that sure enough, Ubuntu supported background lists through the use of XML files. The only problem now was: How do I automatically generate the XML file and set the active background to it?
Behold! My automatic rotating background generator! Below is the code, or you can download it here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #!/bin/bash # # Author: Flynsarmy # Contributor: Ariel Barabas (ariel.baras atGmail) # #interval in seconds INTERVAL=1800 OUTFILE=backgrounds.xml DIR=$(pwd) if [ $1 ]; then if [ $1 == "--help" ]; then echo " Creates the background configuration xml file with 30min of delay between pictures with the images found in the same directory, you can modify that delay entering other number Example: ./createSlideShow.sh 15 makes the delay of 15 minutes" exit else INTERVAL=$(expr $1 \* 60) fi fi echo "<background> <starttime> <year>2009</year> <month>08</month> <day>04</day> <hour>00</hour> <minute>00</minute> <second>00</second> </starttime> " > $OUTFILE while read -r IMG; do if [ "$FIRST_IMG" ]; then echo "<transition> <duration>5.0</duration> <from>$DIR/$LAST_IMG</from> <to>$DIR/$IMG</to> </transition>" >> $OUTFILE else FIRST_IMG="$IMG" fi echo "<static> <duration>$INTERVAL</duration> <file>$DIR/$IMG</file> </static> " >> $OUTFILE done < <(find -name "*.jpg" -o -name "*.png" -o -name "*.gif" | shuf) echo "<transition> <duration>5.0</duration> <from>$DIR/$LAST_IMG</from> <to>$DIR/$FIRST_IMG</to> </transition> </background>" >> $OUTFILE if hash gsettings &>/dev/null; then gsettings set org.gnome.desktop.background picture-uri "file://$DIR/$OUTFILE" else gconftool-2 -t string --set /desktop/gnome/background/picture_filename "$DIR/$OUTFILE" fi |
Remember to chmod +x ./createSlideshow.sh to add execute permissions then ./createSlideshow.sh to run it.
Unlike the original script (written by Ariel Barabas), this version will search recursively from its location for jpg, png and gif files and will work with files/folders containing spaces in their names. It also shuffles the files in the slideshow so if you need to regenerate the background list you won’t get the same list every time.
It defaults to rotating every 3 minutes but you can change this by using ./createSlideshow.sh <minutes>.
Have fun with it!