Results 1 to 1 of 1

Thread: changing images for desktop background script

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default changing images for desktop background script

    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:

    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 ~
    }
    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.

    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.
    Last edited by Storm; 29th February 2012 at 07:09 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Making a job work in background with scp command
    By hk_kamozalwar in forum Shell scripting
    Replies: 3
    Last Post: 16th May 2012, 01:47 PM
  2. [Solved] Linux / Unix Dialog command change background color
    By timtravlr in forum Shell scripting
    Replies: 1
    Last Post: 1st October 2011, 02:29 PM
  3. [Solved] Linux only show process running in background
    By lekhrajdeshmukh in forum Shell scripting
    Replies: 5
    Last Post: 18th March 2011, 06:31 PM
  4. changing csv output using batch script or gawk
    By certteam in forum Coding in General
    Replies: 2
    Last Post: 16th September 2010, 12:12 PM
  5. changing desktop to kde
    By in forum All about FreeBSD/OpenBSD/NetBSD
    Replies: 1
    Last Post: 11th January 2006, 10:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •