[教程]Ubuntu下完整配置自动壁纸切换

来源:http://www.linuxidc.com/Linux/2016-09/135350.html

更原始的来源就不去找了,如果有找到的同学可以回复我我到时改过来www

来源的教程是有效的,但是打脚本的过程有点麻烦并且本身有点小错误(不知道是我看错了还是怎样),这里整理一下发上来

第一步:将壁纸拖入/usr/share/backgrounds/文件夹内

你可以选择删除原先自带的系统壁纸,并将其换为自己的壁纸。

想方便配置的话,在终端中使用命令:

sudo nautilus

来打开管理员权限下的文件管理器,将自己盘里的壁纸拖到这个文件夹里面~

第二步:用bash脚本生成mywallpapers.xml

可以使用vim,emacs,gedit等编辑器进行配置。

你需要将如下代码命名为script.sh并存入任意一个位置。

files=`ls  -u /usr/share/backgrounds | grep -v contest`
last_file='empty'

echo '<background>'
echo '  <starttime>'
echo '    <year>2017</year>'
echo '    <month>9</month>'
echo '    <day>11</day>'
echo '    <hour>00</hour>'
echo '    <minute>00</minute>'
echo '    <second>00</second>'
echo '  </starttime>'

for current_file in $files
do
    if [ "$last_file" = "empty" ]; then
        last_file=$current_file
        first_file=$last_file
        echo '  <static>'
        echo '    <duration>600.0</duration>'
        echo "    <file>/usr/share/backgrounds/$last_file</file>"
        echo '  </static>'
    else
        echo '  <transition>'
        echo '    <duration>3.0</duration>'
        echo "    <from>/usr/share/backgrounds/$last_file</from>"
        echo "    <to>/usr/share/backgrounds/$current_file</to>"
        echo '  </transition>'
        echo '  <static>'
        echo '    <duration>600.0</duration>'
        echo "    <file>/usr/share/backgrounds/$current_file</file>"
        echo '  </static>'
        last_file=$current_file
    fi
done

echo '  <transition>'
echo '    <duration>3.0</duration>'
echo "    <from>/usr/share/backgrounds/$last_file</from>"
echo "    <to>/usr/share/backgrounds/$first_file</to>"
echo '  </transition>'
echo '</background>'

两个transition里的duration是指过渡时所用的时间,两个static里的duration则是指每张壁纸的播放时间,以秒为单位。上方的过渡时间默认为3秒,播放时间为10分钟,可以根据自己喜好更改。

接着使用如下命令生成xml文件:

sh script.sh > mywallpapers.xml

将生成好的文件移动到/usr/share/backgrounds/contest/目录中。

sudo mv mywallpapers.xml /usr/share/backgrounds/contest

第三步:编辑/usr/share/gnome-background-properties/xenial-wallpapers.xml

不同版本下文件名可能会有不同,所以(一般)请选择文件夹下文件名不带ubuntu的那个。这里是16.04版本下的情况。

使用编辑器打开该文件(记得加上sudo),这里以gedit为例,你也可以使用vim或emacs:

sudo gedit /usr/share/gnome-background-properties/xenial-wallpapers.xml

对该文件进行如下的编辑:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
 <wallpaper deleted="false">
   <name>Ubuntu 16.04 Community Wallpapers</name>
   <filename>/usr/share/backgrounds/contest/xenial.xml</filename>
   <options>zoom</options>
 </wallpaper>
//从这里开始插入
 <wallpaper deleted="false">
    <name>My Wallpapers</name>
    <filename>/usr/share/backgrounds/contest/mywallpapers.xml</filename>
    <options>zoom</options>
 </wallpaper>
//到这里结束
...
//下面不要动

保存,退出。

第四步:更改桌面壁纸。

回到桌面,右键,选择更改桌面背景:

在右侧的选项栏中,选择“壁纸”一栏,你会发现这一栏下面有两种壁纸——

当然是选择名为My Wallpapers的那个。

大功告成。

实现的原理和细节可以参考一开始的来源。

原文地址:https://www.cnblogs.com/acxblog/p/7520893.html