Gnome3(Ubuntu)壁纸自动切换

本文介绍如何利用Gnome3自带的gnome-shell功能实现自动切换桌面壁纸,并提供了一个脚本示例,用于生成定制化的壁纸切换配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>
  • 注销重新登陆
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值