Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I keep all my documents on a separate drive from my ubuntu installation, and I have a folder full of nice wallpapers on that drive. How can I make ubuntu automatically search this directory so wallpapers show up in the wallpaper changer dialogue, reached from right clicking on the desktop and selecting Change Desktop Wallpaper?

Edit: I've tried putting a symlink in the /usr/share/backgrounds folder to the other drive and that didn't work.

share|improve this question
add comment

5 Answers

up vote 6 down vote accepted
+50

* EDIT - Second try - and apologies immediately for all the terminal work - hopefully this should just be copying and pasting the highlighted entries*

the folder that holds the details of the gnome wallpapers is called /usr/share/gnome-background-properties/ubuntu-wallpapers.xml

You could edit that file to have wallpaper.../wallpaper sub-sections pointing to your new folder & wallpaper files

Below is a script amended from this forum entry which will regenerate the ubuntu-wallpapers.xml file automatically for a folder containing .png and .jpg files.

copy and paste the contents into a new text file called "ubuntu-wallpaper-generator"

Then execute the file with the syntax

sh ubuntu-wallpaper-generator <path to new wallpaper folder>

This will generate a file called ubuntu-wallpapers.xml in the same folder as where you are running this script.

Safely backup you current xml file i.e.

sudo cp /usr/share/gnome-background-properties/ubuntu-wallpapers.xml /usr/share/gnome-background-properties/ubuntu-wallpapers.xml.backup

the copy in the newly generated file

sudo cp ubuntu-wallpapers.xml /usr/share/gnome-background-properties/ubuntu-wallpapers.xml

Here is that script file I referred to:

#!/bin/bash
#
# This script will take all wallpapers in a given folder and
# make them available as "default" background in the "Change Background" gui
# frontend in Ubuntu.
#
################################################################################

#CONFIG_DIR="/usr/share/gnome-background-properties"
CONFIG_DIR="./"
XML_FILE="$CONFIG_DIR/ubuntu-wallpapers.xml"

if [ $# -ne 1 ]; then
   echo "*** syntax ubuntu-wallpaper-generator <path to wallpaper folder> ***"
   echo "*** for example ***"
   echo "*** ubuntu-wallpaper-generator /usr/share/backgrounds ***"
   exit 1
else
   WALLPAPER_DIR=$1
   echo "*** parameters passed: $1 ***"
fi

#### First check if we have write permissions to the share dirctory. ####
touch $CONFIG_DIR/testfile >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
   echo "**** No permissions to the desktop share directory. ****"
   echo "**** $CONFIG_DIR ****"
   echo "**** Procedure Terminated. ****"
   exit 1
else
   rm $CONFIG_DIR/testfile 2>/dev/null
fi

#### Show the script description message. ###
cat <<EOF

################################################################################
     This script makes all pictures in the $WALLPAPER_DIR
     directory available to all users defined on this system as their
     system-wide GNOME wallpapers.
################################################################################
EOF

#### Fail if the wallpaper directory does not exist. ####
if [ ! -d $WALLPAPER_DIR ]; then
    echo "**** The wallpaper directory \"$WALLPAPER_DIR\" does not exist. ****"
    echo "**** Precedure Terminated. ****"
    exit 1
fi

#### Count the number of jpg/jpeg/png images. ####
numfiles=`ls -1 $WALLPAPER_DIR/*.jpg WALLPAPER_DIR/*.jpeg WALLPAPER_DIR/*.png 2>/dev/null | wc -l`

#### If there are no image files there then exit. ####
if [ $numfiles -eq 0 ]; then
    echo "**** The wallpaper directory \"$WALLPAPER_DIR\" has no images. ****"
    echo "**** Precedure Terminated. ****"
    exit 1
fi

#### Now we create the XML file containing the images for backgrounds. ####
#### Start by creating the header in the XML file. ####
cat <<EOF > $XML_FILE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
EOF

#### Add each file to the XML file. ####
#### Doing it this way makes sure files with spaces in their names are ####
#### handled properly.   (ls .... | while read fname; do)              ####
ls -1 $WALLPAPER_DIR/*.jpg $WALLPAPER_DIR/*.png $WALLPAPER_DIR/*.jpeg 2> /dev/null |
while read image_name; do
   echo "   Adding: `basename "$image_name"`."
   fname=`basename "$image_name"`
   fname="${fname%%\.*}"
   echo "  <wallpaper>"                          >> $XML_FILE
   echo "    <name>$fname</name>"                >> $XML_FILE
   echo "    <filename>$image_name</filename>"   >> $XML_FILE
   echo "    <options>stretched</options>"       >> $XML_FILE
   echo "    <pcolor>#c58357</pcolor>"           >> $XML_FILE
   echo "    <scolor>#c58357</scolor>"           >> $XML_FILE
   echo "    <shade_type>solid</shade_type>"     >> $XML_FILE
   echo "  </wallpaper>"                         >> $XML_FILE
done

#### Create the footer for the XML file. ####
echo "</wallpapers>"                             >> $XML_FILE

cat <<EOF
################################################################################
     You're almost done. copy the generated file ubuntu-wallpapers.xml to the
     folder /usr/shared/gnome-background-properties
     REMEMBER to backup the current ubuntu-wallpaper.xml in that folder first!
################################################################################

EOF
share|improve this answer
1  
This will only set the folder to your own folder. You still have to import the wallpapers to the changer. –  bdr529 Apr 26 '11 at 20:32
    
May be I havent been clear - sorry about that. For example, if your new wallpaper folder was in /media/<somedrive>/<somefolder> then sudo ln -s /media/<somedrive>/<somefolder> backgrounds would list all your new wallpapers. If you wanted also the standard wallpapers, then I would just copy the current backgrounds folder contents to your new wallpaper folder. I've just tested this on Natty - when I choose "new backgrounds" from right clicking the desktop, it displayed the contents of the new folder wallpaper without "importing" –  fossfreedom Apr 26 '11 at 20:42
    
oops - just seen what is wrong ... –  fossfreedom Apr 26 '11 at 21:34
    
works great, makes the wallpaper changer run a little slow because of the extra pictures though. Thanks! –  Slipstream Apr 27 '11 at 8:25
    
Me too, thanks. I put your script and cp in another script and added "gnome-appearance-properties --show-page=background" for showing the change dialog. I start the new script from my menu. –  bdr529 Apr 27 '11 at 12:11
add comment

heres an update:

    #!/bin/bash

    ################################################################################
    # This script will take all wallpapers in a given folder and
    # make them available as options in the "change desktop background" OR "system->pref->apperances"
    # dialog boxes.
    # for ubuntu or debian
    #    wallpapers are in /usr/share/pixmaps/backgrounds/gnome OR /usr/share/backgrounds
    #    config file(s) for the dialog are in /usr/share/gnome-background-properties
    # --that will make them system wide. 
    #
    #ToDo:
    #  paths with spaces.
    ################################################################################

    # put the output in the same directory as this script
    OutDirectory="$( cd "$( dirname "$0" )" && pwd )"
    OutFile="$OutDirectory/gnome-added.xml"

    # options
    options="zoom"      #zoom is best but stretch,center,scale,tile,span
    shade_type="solid"  #horizontal-gradient, vertical-gradient    
    pcolor="#000000"
    scolor="#000000"


    if [ $# -ne 1 ]; then
       echo "*** need path to directory containing files to include."
       echo "*** for example:     /usr/share/backgrounds"
       exit 1
    else
       ScanDirectory=$1
    fi

    #------need to strip and trailing "/" or this writes incorrect file names.
    # not if [ "$lastchr" -eq "/" ]
    # lastchr=`expr substr $ScanDirectory ${#ScanDirectory} 1`  #--OR:
    lastchr=${ScanDirectory#${ScanDirectory%?}}
    if [ "${lastchr}" = "/" ]; then
       ScanDirectory=${ScanDirectory%?}
    fi
    #--operating in same directory as the script? set full path for the xml file
    if [ ${#ScanDirectory} -le 1 ]; then
            ScanDirectory=$OutDirectory
    fi

    # ---does directory exist
    if [ ! -d $ScanDirectory ]; then
        echo "**** The wallpaper directory \"$ScanDirectory\" does not exist. ****"
        echo "**** Precedure Terminated. ****"
        exit 1
    fi
    # ----can we write to it?
    # touch $OutDirectory/testfile >/dev/null 2>/dev/null
    # if [ $? -ne 0 ]; then
    if [ ! -w $OutDirectory ]; then
       echo "**** No permissions to the desktop share directory. ****"
       echo "**** $OutDirectory ****"
       echo "**** Procedure Terminated. ****"
       exit 1
    fi


    #### Count the number of jpg/jpeg/png/svg [tif(f)] images. ####
    numfiles=`ls -1 $ScanDirectory/*.jpg ScanDirectory/*.jpeg ScanDirectory/*.png ScanDirectory/*.svg 2>/dev/null | wc -l`

    #### If there are no image files there then exit. ####
    if [ $numfiles -eq 0 ]; then
        echo "**** The wallpaper directory \"$ScanDirectory\" has no images. ****"
        echo "**** Precedure Terminated. ****"
        exit 1
    fi

    #### Now we create the XML file containing the images for backgrounds. ####
    #### Start by creating the header in the XML file. ####
    cat <<EOF > $OutFile
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
    <wallpapers>
    EOF

    #### Add each file to the XML file. ####
    #### Doing it this way makes sure files with spaces in their names are ####
    #### handled properly.   (ls .... | while read fname; do)              ####
    ls -1 $ScanDirectory/*.jpg $ScanDirectory/*.png $ScanDirectory/*.jpeg $ScanDirectory/*.svg 2> /dev/null |
    while read image_name; do
       fname=`basename "$image_name"`
       echo "   Adding: $fname."

       echo "  <wallpaper deleted=\"false\">"          >> $OutFile
       echo "    <name>$fname</name>"                >> $OutFile
       echo "    <filename>$image_name</filename>"   >> $OutFile
       echo "      <options>$options</options>"       >> $OutFile
       echo "      <pcolor>$pcolor</pcolor>"           >> $OutFile
       echo "      <scolor>$scolor</scolor>"           >> $OutFile
       echo "      <shade_type>$shade_type</shade_type>"     >> $OutFile
       echo "  </wallpaper>"                         >> $OutFile
    done

    #### Create the footer for the XML file. ####
    echo "</wallpapers>"                             >> $OutFile
share|improve this answer
    
Welcome to AskUbuntu! If this is an updated answer, you may want to add it to Fossfreedom's one as an edit while mentioning which version this updated answer pertains to. –  Oyibo Nov 18 '12 at 8:38
add comment

I faced the same problem, and I wrote a python script to edit a custom xml file that can be placed in /usr/share/gnome-background-properties/my-backgrounds.xml. It's on GitHub.

Example usage:

To add space_galaxy.jpeg and fuzz_dog.png to the xml file:

python my-backgrounds.py -a space_galaxy.jpeg fuzzy_dog.png -n "Cool Galaxy" "Cute Dog"

Note that the default xml file is at /usr/share/gnome-background-properties/my-backgrounds.xml (this is where GNOME watches for the xml's). To specify an alternative xml file, use the -x option:

python my-backgrounds.py -a space_galaxy.jpeg -x ~/my-backgrounds.xml

To remove entries from the xml file use the -r option:

python my-backgrounds.py -r "Cool Galaxy" fuzzy_dog.png

This works with GNOME 3.6 and Python 3.3

share|improve this answer
add comment

This is how I do it.

  1. Right click on the Desktop > Change Background.

  2. Click Add on the Background Tab.

  3. Go into the folder, and select all the wallpapers, by clicking on one, and pressing Ctrl + A.

They should be now displayed in the chooser. I am also trying to find a small app that I had used, to automatically change the wallpaper. Ill post when I find it.

I found one called Wally, and its highly recommended, but I remember I hadnt used that one. Anyway, you can install it by typing

sudo apt-get install wally

in a terminal.

To show the wallpapers in the selector, without having to manually update the folder, you will have to add them to /usr/share/backgrounds.

I also was able to list the wallpapers in the chooser, by creating a symlink in the folder.

$ cd /usr/share/backgrounds
$ ln -s /path/to/wallpapers

That might be helpful, because it may not always be convinient to add wallpapers to a folder owned by root everytime.

share|improve this answer
    
I know this imports all of the wallpapers in the folder, but how do I get it to check the folder, so when I add more to the folder, the automatically appear in the chooser, without having to import them again? –  Slipstream Apr 18 '11 at 14:36
    
@Slipstream Edited my answer. –  theTuxRacer Apr 18 '11 at 14:42
    
I added the symlink, which I thought might be one way of doing it before but they still don't seem to show up in there... –  Slipstream Apr 19 '11 at 8:56
    
@Slipstream Yes, indeed. My answer is incorrect. I saw the pictured added, but I might have added them manually, a long time ago, which messed with the results. I am disappoint. Bet you are too. Sorry :( –  theTuxRacer Apr 19 '11 at 17:24
add comment

With CreBS (Create Background Slideshow) you can create the XML files for wallpaper slideshows -- the fullpaths to the images are stored in the XML so no moving of files needed.

https://launchpad.net/crebs

http://www.obfuscatepenguin.net/crebs/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.