Gnome3(Ubuntu)桌布自動切換
阿新 • • 發佈:2018-12-23
Gnome3的gnome-shell自帶自動切換桌布的功能。
1. 分析其自帶的桌布切換功能,可以發現是由2個檔案控制的 不想看的,直接點上面連結看下面第2步
/usr/share/backgrounds/gnome/adwaita-timed.xml
來宣告有哪些桌布,多久執行切換
<background>
<starttime>
<year>2011</year>
<month>11</month>
<day>24</day>
<hour >7</hour>
<minute>00</minute>
<second>00</second>
</starttime>
<!-- This animation will start at 7 AM. -->
<!-- We start with sunrise at 7 AM. It will remain up for 1 hour. -->
<static>
<duration>3600.0</duration>
<file>/usr/share/backgrounds/gnome/adwaita-morning.jpg</file >
</static>
<!-- Sunrise starts to transition to day at 8 AM. The transition lasts for 5 hours, ending at 1 PM. -->
<transition type="overlay">
<duration>18000.0</duration>
<from>/usr/share/backgrounds/gnome/adwaita-morning.jpg</from>
<to>/usr/share/backgrounds/gnome/adwaita-day.jpg</to >
</transition>
<!-- It's 1 PM, we're showing the day image in full force now, for 5 hours ending at 6 PM. -->
<static>
<duration>18000.0</duration>
<file>/usr/share/backgrounds/gnome/adwaita-day.jpg</file>
</static>
<!-- It's 7 PM and it's going to start to get darker. This will transition for 6 hours up until midnight. -->
<transition type="overlay">
<duration>21600.0</duration>
<from>/usr/share/backgrounds/gnome/adwaita-day.jpg</from>
<to>/usr/share/backgrounds/gnome/adwaita-night.jpg</to>
</transition>
<!-- It's midnight. It'll stay dark for 5 hours up until 5 AM. -->
<static>
<duration>18000.0</duration>
<file>/usr/share/backgrounds/gnome/adwaita-night.jpg</file>
</static>
<!-- It's 5 AM. We'll start transitioning to sunrise for 2 hours up until 7 AM. -->
<transition type="overlay">
<duration>7200.0</duration>
<from>/usr/share/backgrounds/gnome/adwaita-night.jpg</from>
<to>/usr/share/backgrounds/gnome/adwaita-morning.jpg</to>
</transition>
</background>
/usr/share/gnome-background-properties/adwaita.xml
來使宣告生效
<?xml version="1.0"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
<wallpaper deleted="false">
<name>Default Background</name>
<filename>/usr/share/backgrounds/gnome/adwaita-timed.xml</filename>
<options>zoom</options>
<shade_type>solid</shade_type>
<pcolor>#3465a4</pcolor>
<scolor>#000000</scolor>
</wallpaper>
</wallpapers>
2. 系統怎麼來,我們就怎麼來
- 編寫控制檔案
switchBG.xml
可以自己輸,不過圖片多就麻煩了,還是用指令碼吧有人發現這生成的檔案跟上面其實有點不同,其實這是我以前ubuntu中的格式,Gnome3也通用的
#!/bin/bash
files=`ls -U /home/mm/圖片/桌布/` //改成自己路徑,下同
last_file='emputy'
echo '<background>'
echo ' <starttime>'
echo ' <year>2018</year>'
echo ' <month>02</month>'
echo ' <day>04</day>'
echo ' <hour>00</hour>'
echo ' <minute>00</minute>'
echo ' <second>00</second>'
echo ' </starttime>'
for current_file in $files
do
if [[ $last_file == 'emputy' ]]
then
echo ' <static>'
echo ' <duration>300.0</duration>'
echo " <file>/home/mm/圖片/桌布/$current_file</file>"
echo ' </static>'
last_file=$current_file
else
echo ' <transition>'
echo ' <duration>5.0</duration>'
echo " <from>/home/mm/圖片/桌布/$last_file</from>"
echo " <to>/home/mm/圖片/桌布/$current_file</to>"
echo ' </transition>'
echo ' <static>'
echo ' <duration>300.0</duration>'
echo " <file>/home/mm/圖片/桌布/$current_file</file>"
echo ' </static>'
last_file=$current_file
fi
done
echo '</background>'
- 複製到目錄
sudo cp switchBG.xml /usr/share/backgrounds/
(其實不復制也應該可以) - 編寫生效檔案
/usr/share/gnome-background-properties/xxx.xml
?xml version="1.0"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
<wallpaper deleted="false">
<name>Wifes</name>
<filename>/usr/share/backgrounds/switchBG.xml</filename> //剛才的路徑
<options>zoom</options>
<shade_type>solid</shade_type>
<pcolor>#3465a4</pcolor>
<scolor>#000000</scolor>
</wallpaper>
</wallpapers>
- 登出重新登陸