來源: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的那個。
大功告成。
實現的原理和細節可以參考一開始的來源。
