Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Bash script to generate backgrounds.xml for gnome

  1. #1
    Join Date
    May 2009
    Beans
    15

    Nautilus / CLI scripts to generate gnome wallpaper stack xml

    I like the automated wallpaper switching in gnome.

    Here is a cli script that generates an xml which can be consumed by the backgrounds config. Full pathnames to the background folders are required.

    Code:
    #!/bin/bash
    # gnome-backgrounds-xmlgen.sh
    #
    # usage:./gnome-backgrounds-xmlgen.sh background_dir_1 background_dir_2 background_dir_3
    #
    # description: simply generate a backgrounds xml that can be consumed by gnome's background configuration
    #
    # authors: ozhoo & browner @ ubuntuforums.org
    #
    # note: only looks for .JPG and .jpg files
    
    # output file
    FILENAME=backgrounds.xml
    
    # start time (any time in the past works)
    YEAR=2009
    MONTH=04
    DAY=02
    HOUR=00
    MINUTE=00
    SECOND=00
    
    # time to show background (seconds)
    WALLDURATION=900.0
    
    # transition time (seconds)
    TRANSDURATION=5.0
    
    # script specifics
    DIRS=$*
    T1="echo -e \t"
    T2="echo -e \t\t"
    
    echo "<background>" > "$FILENAME"
    ${T1}"<starttime>" >> "$FILENAME"
    ${T2}"<year>${YEAR}</year>" >> "$FILENAME"
    ${T2}"<month>${MONTH}</month>" >> "$FILENAME"
    ${T2}"<day>${DAY}</day>" >> "$FILENAME"
    ${T2}"<hour>${HOUR}</hour>" >> "$FILENAME"
    ${T2}"<minute>${MINUTE}</minute>" >> "$FILENAME"
    ${T2}"<second>${SECOND}</second>" >> "$FILENAME"
    ${T1}"</starttime>" >> "$FILENAME"
    
    get_first()
    {
        for d in $DIRS; do
            find "$d"|grep -i .jpg|while read j; do
                echo "$j"
                break
            done
            break
        done
    }
    
    FIRST="$(get_first)"
    
    ${T1}"<static>" >> "$FILENAME"
    ${T2}"<duration>${WALLDURATION}</duration>" >> "$FILENAME"
    ${T2}"<file>${FIRST}</file>" >> "$FILENAME"
    ${T1}"</static>" >> "$FILENAME"
    ${T1}"<transition>" >> "$FILENAME"
    ${T2}"<duration>${TRANSDURATION}</duration>" >> "$FILENAME"
    ${T2}"<from>${FIRST}</from>" >> "$FILENAME"
    
    for d in $DIRS; do
        find "$d"|sort -R|grep -i .jpg|while read j; do
            if [ "$j" == "$FIRST" ]; then
                continue
            else
                ${T2}"<to>${j}</to>" >> "$FILENAME"
                ${T1}"</transition>" >> "$FILENAME"
                ${T1}"<static>" >> "$FILENAME"
                ${T2}"<duration>${WALLDURATION}</duration>" >> "$FILENAME"
                ${T2}"<file>${j}</file>" >> "$FILENAME"
                ${T1}"</static>" >> "$FILENAME"
                ${T1}"<transition>" >> "$FILENAME"
                ${T2}"<duration>${TRANSDURATION}</duration>" >> "$FILENAME"
                ${T2}"<from>${j}</from>" >> "$FILENAME"
            fi
        done
    done
    
    ${T2}"<to>${FIRST}</to>" >> "$FILENAME"
    ${T1}"</transition>" >> "$FILENAME"
    echo "</background>" >> "$FILENAME"
    Here it is in a form consumable by nautilus.

    Code:
    #!/bin/bash
    # 
    # Place this in your ~/.gnome2/nautilus-scripts directory
    #
    # authors: ozhoo & browner @ ubuntuforums.org
    #
    # note: only looks for .JPG and .jpg files
    
    # current location
    CWD="$(pwd)"
    
    # output file
    FILENAME=backgrounds.xml
    
    # start time (any time in the past works)
    YEAR=2009
    MONTH=04
    DAY=02
    HOUR=00
    MINUTE=00
    SECOND=00
    
    # time to show background (seconds)
    WALLDURATION=900.0
    
    # transition time (seconds)
    TRANSDURATION=5.0
    
    # script specifics
    DIRS=$*
    T1="echo -e \t"
    T2="echo -e \t\t"
    
    echo "<background>" > "$FILENAME"
    ${T1}"<starttime>" >> "$FILENAME"
    ${T2}"<year>${YEAR}</year>" >> "$FILENAME"
    ${T2}"<month>${MONTH}</month>" >> "$FILENAME"
    ${T2}"<day>${DAY}</day>" >> "$FILENAME"
    ${T2}"<hour>${HOUR}</hour>" >> "$FILENAME"
    ${T2}"<minute>${MINUTE}</minute>" >> "$FILENAME"
    ${T2}"<second>${SECOND}</second>" >> "$FILENAME"
    ${T1}"</starttime>" >> "$FILENAME"
    
    get_first()
    {
        for d in $DIRS; do
            find "${CWD}/${d}"|grep -i .jpg|while read j; do
                echo "$j"
                break
            done
            break
        done
    }
    
    FIRST="$(get_first)"
    
    ${T1}"<static>" >> "$FILENAME"
    ${T2}"<duration>${WALLDURATION}</duration>" >> "$FILENAME"
    ${T2}"<file>${FIRST}</file>" >> "$FILENAME"
    ${T1}"</static>" >> "$FILENAME"
    ${T1}"<transition>" >> "$FILENAME"
    ${T2}"<duration>${TRANSDURATION}</duration>" >> "$FILENAME"
    ${T2}"<from>${FIRST}</from>" >> "$FILENAME"
    
    for d in $DIRS; do
        find "${CWD}/${d}"|sort -R|grep -i .jpg|while read j; do
            if [ "$j" == "$FIRST" ]; then
                continue
            else
                ${T2}"<to>${j}</to>" >> "$FILENAME"
                ${T1}"</transition>" >> "$FILENAME"
                ${T1}"<static>" >> "$FILENAME"
                ${T2}"<duration>${WALLDURATION}</duration>" >> "$FILENAME"
                ${T2}"<file>${j}</file>" >> "$FILENAME"
                ${T1}"</static>" >> "$FILENAME"
                ${T1}"<transition>" >> "$FILENAME"
                ${T2}"<duration>${TRANSDURATION}</duration>" >> "$FILENAME"
                ${T2}"<from>${j}</from>" >> "$FILENAME"
            fi
        done
    done
    
    ${T2}"<to>${FIRST}</to>" >> "$FILENAME"
    ${T1}"</transition>" >> "$FILENAME"
    echo "</background>" >> "$FILENAME"
    CHEERS
    Last edited by ozhoo; February 21st, 2011 at 01:54 AM.

  2. #2
    Join Date
    Dec 2009
    Beans
    1

    Smile Re: Bash script to generate backgrounds.xml for gnome

    Hey, man!

    Great little script! Already started using it! =)
    Thanks much!

    Pusi85 form HUNGARY

  3. #3
    Join Date
    May 2009
    Beans
    15

    Re: Bash script to generate backgrounds.xml for gnome

    @pusi85 cheers!

    Quote Originally Posted by Pusi85 View Post
    Hey, man!

    Great little script! Already started using it! =)
    Thanks much!

    Pusi85 form HUNGARY

  4. #4
    Join Date
    Mar 2006
    Location
    Edinburgh, Scotland, UK
    Beans
    103
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash script to generate backgrounds.xml for gnome

    Many thanks ozhoo! Great little script
    Registered Linux User: 443527 | Registered Ubuntu User: 12253 | Last.fm profile
    Dell Inspiron 9300 | Pentium M 730 @ 2.27 GHz | GeForce 6800

  5. #5
    Join Date
    Mar 2006
    Location
    Edinburgh, Scotland, UK
    Beans
    103
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Bash script to generate backgrounds.xml for gnome

    Quote Originally Posted by BrowneR View Post
    Many thanks ozhoo! Great little script
    Just wanted to say I also modified the two "find" lines in your script to give me a random sorted list instead of alphabetical. This way I can have one folder of photographs and one folder of computer generated images and get a nice mixture of the two when it is displayed.

    In case anyone else is interested just change the two find lines so they read as follows:

    Code:
    find "$d"|sort -R|grep -i .jpg|while read j; do
    Cheers,
    Chris
    Registered Linux User: 443527 | Registered Ubuntu User: 12253 | Last.fm profile
    Dell Inspiron 9300 | Pentium M 730 @ 2.27 GHz | GeForce 6800

  6. #6
    Join Date
    Jun 2010
    Beans
    7

    Re: Bash script to generate backgrounds.xml for gnome

    Hi,

    I am totally new to the Ubuntu scene, recently upgraded from Windows 7 whereby I had this ability to automatically change backgrounds.

    I have tried numerous times to do this but coding is just not in my blood.


    Can someone please explain how to set a specific folder of photos for this script?


    All the best,

    Andrew

  7. #7
    Join Date
    May 2009
    Beans
    15

    Re: Bash script to generate backgrounds.xml for gnome

    @browner Sweet. This makes more sense. Edited original post & added your input

    Quote Originally Posted by BrowneR View Post
    Just wanted to say I also modified the two "find" lines in your script to give me a random sorted list instead of alphabetical. This way I can have one folder of photographs and one folder of computer generated images and get a nice mixture of the two when it is displayed.

    In case anyone else is interested just change the two find lines so they read as follows:

    Code:
    find "$d"|sort -R|grep -i .jpg|while read j; do
    Cheers,
    Chris

  8. #8
    Join Date
    May 2009
    Beans
    15

    Re: Bash script to generate backgrounds.xml for gnome

    @AnThoMan

    Comment out the line DIRS=$*

    and replace with

    DIRS=/path/to/your/backgrounds

    Quote Originally Posted by AnThoMan View Post
    Hi,

    I am totally new to the Ubuntu scene, recently upgraded from Windows 7 whereby I had this ability to automatically change backgrounds.

    I have tried numerous times to do this but coding is just not in my blood.


    Can someone please explain how to set a specific folder of photos for this script?


    All the best,

    Andrew

  9. #9
    Join Date
    May 2010
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Bash script to generate backgrounds.xml for gnome

    this works great, thanks a lot!

  10. #10
    Join Date
    May 2009
    Location
    Jah's Pocket
    Beans
    733
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Bash script to generate backgrounds.xml for gnome

    Ever thought of making a nautilus script out of this? You could then just click and highlight the files/folders and generate the file without the command line.
    MyBlog
    Sledgehammer engineering, if it doesn't work, hit it damn hard.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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