Hi all good people,
the other day I was visiting my girl friend who gave me a load of great images of her and me, and I thought: "Wow, these images are great! It would be nice to have them all changing on my desktop background." And so the following script was born:
Input to this script is a folder filled with images that you want to be changing on your background. Output of this script is a simple xml file which is then used to activate desktop images to change as a background. I use Ubuntu Maverick. I want to modify this code to be shorter and more efficient and I want to shuffle the images.Code:#!/bin/bash desk(){ dir=$1 echo "dir=$dir" #create 'background-1.xml' file namef=background-1 extf=xml echo "" > $dir$namef.$extf echo "<background> <starttime> <year>2012</year> <month>02</month> <day>21</day> <hour>10</hour> <minute>05</minute> <second>00</second> </starttime>" >> $dir$namef.$extf #remove tmp cd $dir; rm tmp.txt #list of files in source directory ls $dir > tmp.txt #total number of files in source directory number=$(ls $dir | wc -l) for (( i = 1; i <= $(expr $number - 1); i++ )) do current=$(head -n $i tmp.txt | tail -n 1) next=$(head -n $(expr $i + 1) tmp.txt | tail -n 1) first=$(head -n 1 tmp.txt | tail -n 1) final=$(head -n $number tmp.txt | tail -n 1) IFS=. read -r name extension <<< "$current" read -r next_n next_e <<< "$next" read -r first_n first_e <<< "$first" read -r final_n final_e <<< "$final" #check if current file is .JPG image echo "$extension" | grep -s 'JPG' if [ $? -eq 0 ] ; then #add following text in deskfile echo "<static> <duration>300.0</duration> <file>$dir$name.$extension</file> </static> <transition> <duration>1.0</duration> <from>$dir$name.$extension</from> <to>$dir$next_n.$next_e</to> </transition>" >> $dir$namef.$extf else echo "$name.$extension is not an image file" fi done echo "<static> <duration>300.0</duration> <file>$dir$final_n.$final_e</file> </static> <transition> <duration>1.0</duration> <from>$dir$final_n.$final_e</from> <to>$dir$first_n.$first_e</to> </transition>" >> $dir$namef.$extf echo "</background>" >> $dir$namef.$extf cd ~ }
1. Is there more intelligent way of going through files other then my head-tail approach?
2. How do I make the images to shuffle?
3. Obviously I don't want to 4.JPG to be next image after each image. How do I make next image i+1 in all but last image, which points to the first one?
4. Do I need <transition> part if I don't need any transitions?
5. How do I fit images to screen?
This script works file even though there is next image 4.JPG in all of them. I don't know how. Please help me make this script better.
Best regards brothers and sisters
Storm
Edit: I just noticed that instead of /usr/share/backgrounds/ you can use any directory to store your background images, so I changed that part. Still I get images that are cropped to my screen and I would like them to fit screen. Added 5th issue.

Reply With Quote