Ubuntu之下如何开启壁纸自动切换

  1. 选择一个图片文件夹,将需要用到的壁纸放在该文件下

  2. 在该文件夹下运行如下脚本:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # Name: slidexml.py
    # Author: EthanZ6174
    # Email: <[email protected]>
    # Site: http://www.noslog.com
    # Licence: GPLv3
    # Version: 091127
    
    import glob, os
    import shutil
    import time
    
    
    curdir = os.getcwd()
    os.chdir(curdir)
    currentFilelist = glob.glob('*.*')
    currentImageFiles = glob.glob('*.jpg')
    
    currentTime = time.localtime()
    length = len(currentImageFiles)
    
    for i in currentFilelist:
     if i == 'backgroundslide.xml':
      os.remove(i)
    
    f = file('backgroundslide.xml', 'w')
    
    f.write('<background>\n')
    f.write('\t<starttime>\n')
    f.write('\t\t<year>' + str(currentTime.tm_year) + '</year>\n')
    f.write('\t\t<month>' + str(currentTime.tm_mon) + '</month>\n')
    f.write('\t\t<day>' + str(currentTime.tm_mday) + '</day>\n')
    f.write('\t\t<hour>' + str(currentTime.tm_hour) + '</hour>\n')
    f.write('\t\t<minute>' + str(currentTime.tm_min) + '</minute>\n')
    f.write('\t\t<second>' + str(currentTime.tm_sec) + '</second>\n')
    f.write('\t</starttime>\n')
    f.write('<!--This animation will start at the time it created-->\n')
    
    for i in currentImageFiles:
     length = length - 1
     print length
     #print curdir
     #print currentImageFiles[1]
     f.write('\t<static>\n')
     f.write('\t\t<duration>595.0</duration>\n')
     f.write('\t\t<file>' + curdir + '/' + currentImageFiles[length] +'</file>\n')
     f.write('\t</static>\n')
     f.write('\t<transition>\n')
     f.write('\t\t<duration>5.0</duration>\n')
     f.write('\t\t<from>' + curdir + '/' + currentImageFiles[length] + '</from>\n')
     if length >= 1:
      f.write('\t\t<to>' + curdir + '/' + currentImageFiles[length-1] + '</to>\n')
     if length <1:
      f.write('\t\t<to>' + curdir + '/' + currentImageFiles[len(currentImageFiles)-1] + '</to>\n')
     f.write('\t</transition>\n')
    
    f.write('</background>\n')
    f.close()

     3. 将生成的background.xml加入桌面背景选择中

附录:

<background> 
  <starttime>   <!-- 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. -->   <!-- "animation"动画的意思 -->
  <static>  <!-- "static"静态的意思 -->
    <duration>1800.0</duration>  <!-- duration标签设置持续的时间,以秒为单位。--> 
    <file>/usr/share/backgrounds/cosmos/cloud.jpg</file> <!-- file标签指定壁纸存放的路径 -->
  </static> 
  <transition> <!--"transition"切换的意思 -->
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/cloud.jpg</from><!--from ... to从壁纸A切换到壁纸B。--> 
    <to>/usr/share/backgrounds/cosmos/comet.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/comet.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/comet.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/earth-horizon.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/earth-horizon.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/earth-horizon.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/blue-marble-west.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/blue-marble-west.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/blue-marble-west.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/galaxy-ngc3370.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/galaxy-ngc3370.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/galaxy-ngc3370.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/helix-nebula.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/helix-nebula.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/helix-nebula.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/jupiter.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/jupiter.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/jupiter.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/sombrero.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/sombrero.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/sombrero.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/whirlpool.jpg</to> 
  </transition> 
  <static> 
    <duration>1800.0</duration> 
    <file>/usr/share/backgrounds/cosmos/whirlpool.jpg</file> 
  </static> 
  <transition> 
    <duration>5.0</duration> 
    <from>/usr/share/backgrounds/cosmos/whirlpool.jpg</from> 
    <to>/usr/share/backgrounds/cosmos/cloud.jpg</to> 
  </transition> 
</background> 

你可能感兴趣的:(python,OS,ubuntu,F#,Comet)