如何为墙纸设置另一个搜索目录?


12

我将所有文档都与ubuntu安装放在单独的驱动器上,并且在该驱动器上有一个装满漂亮壁纸的文件夹。如何使ubuntu自动搜索此目录,以使墙纸显示在墙纸更换器对话框中,可以通过右键单击桌面并选择“ 更改桌面墙纸”来进行访问

编辑:我试图将符号链接放在/ usr / share / backgrounds文件夹中到另一个驱动器,但是没有用。


以下所有答案的注释:您可以创建$HOME/.local/share/gnome-background-properties/my-wallpapers.xml和使用它,而不用编辑系统后台文件。
Zan Lynx 2014年

Answers:


9

*编辑-第二次尝试-并对所有终端工作立即道歉-希望这应该只是复制并粘贴突出显示的条目*

包含gnome壁纸详细信息的文件夹称为/usr/share/gnome-background-properties/ubuntu-wallpapers.xml

您可以编辑该文件以使其具有墙纸... /墙纸小节,指向您的新文件夹和墙纸文件。

以下是此论坛条目中经过修改的脚本,它将自动为包含.png和.jpg文件的文件夹重新生成ubuntu-wallpapers.xml文件。

复制内容并将其粘贴到一个名为“ ubuntu-wallpaper-generator”的新文本文件中

然后使用语法执行文件

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

这将在与运行此脚本相同的文件夹中生成一个名为ubuntu-wallpapers.xml的文件。

安全地备份您当前的xml文件,即

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

新生成文件中的副本

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

这是我提到的脚本文件:

#!/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

1
这只会将文件夹设置为您自己的文件夹。您仍然必须将墙纸导入到转换器。
bdr529 2011年

可能我还不清楚-对此感到抱歉。例如,如果您的新墙纸文件夹位于/ media / <somedrive> / <somefolder>中,那么sudo ln -s / media / <somedrive> / <somefolder>背景将列出所有新墙纸。如果您还需要标准墙纸,那么我只需将当前backgrounds文件夹内容复制到您的新墙纸文件夹中即可。我刚刚在Natty上进行了测试-当我从右键单击桌面选择“新背景”时,它显示了新文件夹墙纸的内容,而没有“导入”
fossfreedom

哎呀-刚刚看错了...
fossfreedom

效果很好,但由于额外的图片,使得壁纸更换器的运行速度有些慢。谢谢!
Slipstream

我也是,谢谢。我将您的脚本和cp放在另一个脚本中,并添加了“ gnome-appearance-properties --show-page = background”以显示更改对话框。我从菜单中启动新脚本。
bdr529 2011年


1

继承人更新:

    #!/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

欢迎来到AskUbuntu!如果这是更新的答案,则您可能希望将其添加到Fossfreedom的编辑中,同时提及此更新的答案属于哪个版本。
奥伊波(Oyibo)2012年

1

我遇到了同样的问题,我编写了一个python脚本来编辑可放在中的自定义xml文件/usr/share/gnome-background-properties/my-backgrounds.xml。在GitHub上

用法示例:

要添加space_galaxy.jpegfuzz_dog.pngXML文件:

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

请注意,默认的xml文件位于/usr/share/gnome-background-properties/my-backgrounds.xml(GNOME监视xml的位置)。要指定备用xml文件,请使用以下-x选项:

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

要从xml文件中删除条目,请使用以下-r选项:

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

这适用于GNOME 3.6和Python 3.3


0

这就是我的方法。

  1. 右键单击桌面>更改背景。

  2. 在“背景”选项卡上,单击“添加”。

  3. 该文件夹,并选择所有壁纸,通过点击一个,然后按Ctrl+ A

现在,它们应该显示在选择器中。我还试图找到一个我曾经使用过的小应用程序,以自动更改墙纸。当我找到它的时候会发帖。

我找到了一个叫Wally的手机,强烈推荐它,但是我记得我没有用过那个。无论如何,您可以通过键入以下内容进行安装

sudo apt-get install wally

在一个终端。

要在选择器中显示墙纸,而不必手动更新文件夹,则必须将它们添加到中/usr/share/backgrounds

通过在文件夹中创建符号链接,我还能够在选择器中列出墙纸。

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

这可能会有所帮助,因为每次将墙纸添加到root拥有的文件夹可能并不总是很方便。


我知道这会导入文件夹中的所有墙纸,但是如何获取它来检查文件夹,所以当我向文件夹中添加更多墙纸时,它会自动出现在选择器中,而无需再次导入它们?
Slipstream

@Slipstream编辑了我的答案。
theTuxRacer 2011年

我添加了符号链接,我认为以前可能是这样做的一种方法,但是它们似乎仍然没有出现在其中……
Slipstream

@Slipstream是的,的确如此。我的答案不正确。我看到了添加的图片,但是很久以前我可能已经手动添加了它们,结果变得混乱了。我很失望 打赌你也是。抱歉:(
theTuxRacer 2011年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.