Heijastin

Gnome に壁紙を追加する

Gnome はなぜ壁紙ひとつでこんなに面倒なのか。

Xfce なら ~/.local/share/xfce4/backdrops に KDE なら ~/.kde/share/wallpapers に壁紙を置いておけば、自分の好きな壁紙は普通に選べる。しかし Gnome だけは壁紙のために .xml ファイルを作成する必要がある。なので、自動で .xml を生成する以下のスクリプトを使う。

壁紙用のスクリプト

以下のスクリプトを gedit にコピペして AddWalls.sh などと名前をつけて保存する。

#!/bin/bash
#
# This script will take all wallpapers in $WALLPAPER_DIR and
# make them available as "default" background in the "Change Background" gui
# frontend in Ubuntu.
#
# Basically what it does is create an xml file in the
# /usr/share/gnome-background-properties directory which is read whenever a
# user logs into the system.
#
# All that should need changing to work in any other user's system is:
# WALLPAPER_DIR  (line 15)
# XML_FILE       (line 17)
################################################################################
WALLPAPER_DIR="/home/自分の名前/好きなフォルダ"
CONFIG_DIR="/usr/share/gnome-background-properties"
XML_FILE="$CONFIG_DIR/shared-wallpapers.xml"

#### 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.

     This script should be run as "root" or with "sudo".
     e.g. sudo $0
################################################################################
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>zoom</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

#### Lastly display a message to inform caller to logout and back in. ####
cat <<EOF
################################################################################
     You're almost done. Log out and back in. Invoke the Desktop Background
     Change application again, and all your selected wallpapers should be
     available to use for all users.
################################################################################

EOF

次いで「WALLPAPER_DIR=”/home/自分の名前/好きなフォルダ”」と書いてある場所を好みに変更。そしたら sudo さんで AddWalls.sh を端末にコピペして Enter すれば終わり。このスクリプトは親切設定で、オリジナルの .xml は書き換えずに、新規 .xml を作成する。

sudo ~/AddWalls.sh

Resource

出典はこちら:10.10 – How do I set another search directory for wallpapers? – Ask Ubuntu – Stack Exchange Ubuntu 10.10 の時のネタ。Gnome 4 ではデスクトップのアイコン位置を変更するために Objective-C で記述されたスクリプトが必要になるらしい。

Tags