让 Ubuntu 自动更换桌面壁纸并没有 win10 下那么简单,需要修改一些相关的配置项,主要是两个文件:
修改xenial.xml文件
修改 xenial.xml 文件的工作比较繁杂,且重复度比较高,这个时候就需要利用咱们的计算机思维了,写一个小脚本来实现
cd /usr/share/backgrounds/
sudo gedit background.sh
将代码拷贝到 background.sh 文件中(/usr/share/backgrounds 这是我存放壁纸的路径,如果你的不是,请自行修改)
path=/usr/share/backgrounds
files=`ls -U $path`
last_file='empty'
echo '<background>'
echo ' <starttime>'
echo ' <year>2018</year>'
echo ' <month>05</month>'
echo ' <day>08</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
echo ' <static>'
echo ' <duration>297.0</duration>'
echo " <file>$path/$last_file</file>"
echo ' </static>'
else
echo ' <transition>'
echo ' <duration>3.0</duration>'
echo " <from>$path/$last_file</from>"
echo " <to>$path/$current_file</to>"
echo ' </transition>'
echo ' <static>'
echo ' <duration>297.0</duration>'
echo " <file>$path/$current_file</file>"
echo ' </static>'
last_file=$current_file
fi
done
echo '</background>'
创建一个 mybackground.xml 的文件,并将相关配置写入文件
chmod 755 background.sh
sudo gedit mybackground.xml
sudo chmod 777 mybackground.xml
./background.sh > mybackground.xml
将 mybackground.xml 拷贝到 ./contest/ 目录下,有兴趣的朋友可以打开 ./contest/ 下的 xenial.xml 看一下,这个文件和咱们的 mybackground.xml 高度相似,其实我们要做的就是用 mybackground.xml 替换原有的xenial.xml ,只不过没有在原文件上修改,相当于做了个备份
cp mybackground.xml ./contest/
修改 xenial-wallpapers.xml文件
修改之前做好备份是个好习惯
cd /usr/share/gnome-background-properties/
sudo cp xenial-wallpapers.xml xenial-wallpapers_bak.xml
sudo gedit xenial-wallpapers.xml
在该文件中添加上,name 是随便设的,filename就是我们之前创建好的 mybackground.xml 的路径
<wallpaper deleted="false">
<name>mybackground</name>
<filename>/usr/share/backgrounds/contest/mybackground.xml</filename>
<options>zoom</options>
</wallpaper>
xenial-wallpapers.xml 文件
最后单击右键,进行桌面背景设置,选择我们之前配置好的桌面即可,名字就是你之前随便起的那个
好了,大功告成,开始愉快的欣赏自己新的壁纸吧,有什么问题欢迎留言,附上一张成果图
参考博客:
https://www.cnblogs.com/youxia/p/linux030.html
https://blog.csdn.net/deltaforce_eagle/article/details/52853223