Ubuntu下批量壁纸自动更新的方法
要在ubuntu上实现壁纸的动态更换,首先要记住两个路径下的文件/usr/share/backgrounds
这里是系统存放壁纸和壁纸动态更换脚本的地方,脚本在contest下,以.xml结尾的就是控制播放的脚本了;/usr/share/gnome-background-properties
这里的.xml和/usr/share/backgrounds/contest/下的mxl不同;这里的.xml文件是实现壁纸在系统设置中呈现,并加载动态更换脚本的;
/usr/share/backgrounds/contest/groovy.xml文件原始内容如下(仅用做参考和备份),不对这个文件做修改
<background>
<starttime>
<year>2009</year>
<month>08</month>
<day>04</day>
<hour>00</hour>
<minute>00</minute>
<second>00</second>
</starttime>
<!-- This animation will start at midnight. -->
<static>
<duration>1795.0</duration>
<file>/usr/share/backgrounds/Landscape_Photography_Of_Mountains_by_Simon_Berger.jpg</file>
</static>
<transition>
<duration>5.0</duration>
<from>/usr/share/backgrounds/Landscape_Photography_Of_Mountains_by_Simon_Berger.jpg</from>
<to>/usr/share/backgrounds/Silver_Back_Gorilla_by_Mike_Arney.jpg</to>
</transition>
<static>
<duration>1795.0</duration>
<file>/usr/share/backgrounds/Silver_Back_Gorilla_by_Mike_Arney.jpg</file>
</static>
<transition>
<duration>5.0</duration>
<from>/usr/share/backgrounds/Silver_Back_Gorilla_by_Mike_Arney.jpg</from>
<to>/usr/share/backgrounds/Camera_Film_by_Markus_Spiske.jpg</to>
</transition>
<static>
<duration>1795.0</duration>
<file>/usr/share/backgrounds/Camera_Film_by_Markus_Spiske.jpg</file>
</static>
<transition>
<duration>5.0</duration>
<from>/usr/share/backgrounds/Camera_Film_by_Markus_Spiske.jpg</from>
<to>/usr/share/backgrounds/Colored_Pencils_by_Jess_Bailey.jpg</to>
</transition>
<static>
<duration>1795.0</duration>
<file>/usr/share/backgrounds/Colored_Pencils_by_Jess_Bailey.jpg</file>
</static>
<transition>
<duration>5.0</duration>
<from>/usr/share/backgrounds/Colored_Pencils_by_Jess_Bailey.jpg</from>
<to>/usr/share/backgrounds/Abstract_Painting_Photo_by_Pierre_Chatel-Innocenti.jpg</to>
</transition>
<static>
<duration>1795.0</duration>
<file>/usr/share/backgrounds/Abstract_Painting_Photo_by_Pierre_Chatel-Innocenti.jpg</file>
</static>
<transition>
<duration>5.0</duration>
<from>/usr/share/backgrounds/Abstract_Painting_Photo_by_Pierre_Chatel-Innocenti.jpg</from>
<to>/usr/share/backgrounds/Gorilla_Wallpaper_Grey_4096x2304.png</to>
</transition>
<static>
<duration>1795.0</duration>
<file>/usr/share/backgrounds/Gorilla_Wallpaper_Grey_4096x2304.png</file>
</static>
<transition>
<duration>5.0</duration>
<from>/usr/share/backgrounds/Gorilla_Wallpaper_Grey_4096x2304.png</from>
<to>/usr/share/backgrounds/Landscape_Photography_Of_Mountains_by_Simon_Berger.jpg</to>
</transition>
</background>
/usr/share/gnome-background-properties/groovy-wallpapers.xml文件原始内容如下(仅用做参考和备份),不对这个文件做修改
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
<wallpaper deleted="false">
<name>Ubuntu 20.10 Community Wallpapers</name>
<filename>/usr/share/backgrounds/contest/groovy.xml</filename>
<options>zoom</options>
</wallpaper>
<wallpaper>
<name>Abstract Painting Photo</name>
<filename>/usr/share/backgrounds/Abstract_Painting_Photo_by_Pierre_Chatel-Innocenti.jpg</filename>
<options>zoom</options>
<pcolor>#000000</pcolor>
<scolor>#000000</scolor>
<shade_type>solid</shade_type>
</wallpaper>
<wallpaper>
<name>Camera Film</name>
<filename>/usr/share/backgrounds/Camera_Film_by_Markus_Spiske.jpg</filename>
<options>zoom</options>
<pcolor>#000000</pcolor>
<scolor>#000000</scolor>
<shade_type>solid</shade_type>
</wallpaper>
<wallpaper>
<name>Colored Pencils</name>
<filename>/usr/share/backgrounds/Colored_Pencils_by_Jess_Bailey.jpg</filename>
<options>zoom</options>
<pcolor>#000000</pcolor>
<scolor>#000000</scolor>
<shade_type>solid</shade_type>
</wallpaper>
<wallpaper>
<name>Landscape Photography Of Mountains</name>
<filename>/usr/share/backgrounds/Landscape_Photography_Of_Mountains_by_Simon_Berger.jpg</filename>
<options>zoom</options>
<pcolor>#000000</pcolor>
<scolor>#000000</scolor>
<shade_type>solid</shade_type>
</wallpaper>
<wallpaper>
<name>Silver Back Gorilla</name>
<filename>/usr/share/backgrounds/Silver_Back_Gorilla_by_Mike_Arney.jpg</filename>
<options>zoom</options>
<pcolor>#000000</pcolor>
<scolor>#000000</scolor>
<shade_type>solid</shade_type>
</wallpaper>
</wallpapers>
以上两个文件最好做下备份,然后将这两个文件的备份文件使用 方法禁用掉;这样在这两个文件上就可以*修改了;
下载壁纸
直接贴大佬分享的帖子??
Python批量下载壁纸
生成控制更换xml文件脚本
files=`ls -U /usr/share/backgrounds | grep -v contest` # /usr/share/backgrounds 脚本运行的路径
last_file=‘empty‘
echo ‘<background>‘
echo ‘ <startting>‘
echo ‘ <year>2020</year>‘
echo ‘ <month>11</month>‘
echo ‘ <day>4</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>300.0</duration>‘
echo " <file>/usr/share/backgrounds/$last_file</file>"
echo ‘ </static>‘
else
echo ‘ <transition>‘
echo ‘ <duration>5.0</duration>‘
echo " <from>/usr/share/backgrounds/$last_file</from>"
echo " <to>/usr/share/backgrounds/$current_file</to>"
echo ‘ </transition>‘
echo ‘ <static>‘
echo ‘ <duration>300.0</duration>‘
echo " <file>/usr/share/backgrounds/$current_file</file>"
echo ‘ </static>‘
last_file=$current_file
fi
done
echo ‘</background>‘
# 使用方法说明
# 新建一个文件.xml在图片目录下
# 执行这个脚本 ./backgrounds.sh>/usr/share/backgrounds/contest/black.xml 完成图片目录的填写
# 最后将这个文件复制到/usr/sh/gnome-background-properties 下生效,如果不生效,就把默认xml的路径指向当前这个文件
生成系统壁纸显示列表xml文件脚本
path = /usr/share/backgrounds/Black # 设置操作文件的目录地址,这里将图片放在了/usr/share/backgrounds下的Black文件夹里
files=`ls -U $path | grep -v contest`
last_file=‘empty‘
echo ‘<?xml version="1.0" encoding="UTF-8"?>‘
echo ‘<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">‘
echo ‘<wallpapers>‘
echo ‘ <wallpaper deleted="false">‘
echo ‘ <name>Ubuntu 20.10 Community Wallpapers</name>‘
echo ‘ <filename>/usr/share/backgrounds/contest/black.xml</filename>‘
echo ‘ <options>zoom</options>‘
echo ‘ </wallpaper>‘
for current_file in $files
do
last_file=$current_file
file_name=${last_file##*/}
#jpg_name = "extension: ${last_file##*.}"
if [[ $last_file == ‘empty‘]]
then
echo ‘‘
else
echo ‘ <wallpaper>‘
echo " <name>${last_file%.*}</name>"
echo " <filename>/usr/share/backgrounds/black-backgrounds/$last_file</filename>"
echo ‘ <options>zoom</options>‘
echo ‘ <pcolor>#000000</pcolor>‘
echo ‘ <scolor>#000000</scolor>‘
echo ‘ <shade_type>solid</shade_type>‘
echo ‘ </wallpaper>‘
last_file=$current_file
fi
done
echo ‘</wallpapers>‘
# 使用方法 `sudo ./test.sh>test.xml` 格式: sudo 脚本路径 > 生成xml路径
# sudo ./black-wallpapers.sh>/usr/share/gnome-background-properties/black-wallpapers.xml
使用详细方法