ubuntu 中设置动态壁纸

2018-03-30  本文已影响0人  忆斐

为了开发android 功能,ubuntu系统也使用了好久时间,作为一个经常使用的系统,不捣鼓捣鼓就太平淡,根据网上的一些介绍,搞了一个动态壁纸出来,用来定时更换壁纸。

首先创建一个文件夹,里面三个文件,其余根据自己喜好放入壁纸文件。


第一个文件addbackground.sh,需要可执行权限

sudo rm -rf /usr/share/backgrounds/test
sudo mkdir /usr/share/backgrounds/test
sudo cp  *.jpg /usr/share/backgrounds/test/
. makelist.sh > background.xml
sudo cp background.xml /usr/share/backgrounds/test/
sudo cp cust-wallpapers.xml /usr/share/gnome-background-properties/

gsettings set org.gnome.desktop.background picture-uri 'file:///usr/share/backgrounds/test/background.xml'

第二个文件,用于拷贝到gnome-background-properties,这样设置里面就可以选择作为动态壁纸

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
 <wallpaper deleted="false">
   <name>wentao wallpaper</name>
   <filename>/usr/share/backgrounds/test/background.xml</filename>
   <options>zoom</options>
 </wallpaper>
</wallpapers>

第三个文件makelist.sh 也需要可执行权限

#!/bin/bash
# wentao add 2017.6.27

#get current path
basepath=$(cd `dirname $0`; pwd)

#get all jpg wallpapers
files=`ls  $basepath |grep jpg`

lastfile='empty'

echo '<background>'
echo '    <starttime>'
echo '        <year>2017</year>'
echo '        <month>3</month>'
echo '        <day>15</day>'
echo '        <hour>00</hour>'
echo '        <minute>00</minute>'
echo '        <second>00</second>'
echo '    </starttime>'

for current_file in $files
do
        if [[ $lastfile == 'empty' ]]
        then
                lastfile=$current_file
                echo '    <static>'
                echo '        <duration>300.0</duration>'
                echo "       <file>/usr/share/backgrounds/test/$lastfile</file>"
                echo '    </static>'
        else
                echo '    <transition>'
                echo '         <duration>5.0</duration>'
                echo "         <from>/usr/share/backgrounds/test/$lastfile</from>"
                echo "         <to>/usr/share/backgrounds/test/$current_file</to>"
                echo '    </transition>'
                echo '    <static>'
                echo '         <duration>300.0</duration>'
                echo "        <file>/usr/share/backgrounds/test/$current_file</file>"
                echo '    </static>'
                lastfile=$current_file
        fi
done

echo '</background>'

设置完成以后,运行 ./addbackgroundd.sh,就可以设置动态壁纸了,如果想更换动态壁纸里的图片,只要更新当前文件夹里面的图片就可以了。

上一篇下一篇

猜你喜欢

热点阅读