|
|

楼主 |
发表于 2007-2-17 12:04:44
|
显示全部楼层
设置随机桌面 背景
一、工具准备
fluxbox-1.0rc2-2的fbsetbg程序
WindowMaker-0.92.0-23的wmsetbg程序
刚开始玩suse时不知道哪些该装不该装,所以以前就统统装好了,一看都有,感觉很舒服。
二、新建执行脚本/home/name/random-bg.py
#! /usr/bin/env python
"""
wallpaper - finds a random picture and sets it as wallpaper
you need another program (this uses bsetbg) for actually
setting the wallpaper
In a unix/linux/bsd system, you can schedule this to run regularly
using crontab. For example, I run this every hour. So I go
to a shell and run
crontab -e
This opens up my crontab file. I add the following line:
01 * * * * /usr/local/bin/wallpaper > /dev/null
learn more about cron format at
http://www.uwsg.iu.edu/edcert/sl ... ation/crontab5.html
"""
# all the folders you want to scan
folders = [
#'/home/name/picture/cg',
'/home/name/picture/0915',
'/home/name/picture/green',
'/home/name/picture/linux',
'/home/name/picture/luzhu',
'/home/name/picture/winxp',
'/home/name/picture/lanling',
'/home/name/picture/classic',
#上面是所有的桌面文件夹
]
# these are the valid image types - case sensitive
use_types = ['.jpg', '.gif', '.png']
# the command to execute for setting wallpaper. %s will be
# substituted by the image path
#cmd = "bsetbg -f %s"
cmd = "fbsetbg -r %s"
# ---------------- main routine ------------------------------
import os
from random import choice
# initialize a list to hold all the images that can be found
imgs = []
for d in folders: #for each item in folders
if os.path.exists(d) and os.path.isdir(d): #is it a valid folder?
try: imgs.append(d)
# for f in os.listdir(d): #get all files in that folder
#
# try: #splitext[1] may fail
# if os.path.splitext(f)[1] in use_types: #is that file of proper type?
# imgs.append(d + os.sep + f) #if so, add it to our list
except:
pass
wallpaper = choice(imgs) #get a random entry from our list
#print cmd % wallpaper
os.system(cmd % wallpaper) #execute the command
三、设置自动启动
创建链接 ln-s /home/name/random-bg.py /usr/local/bin/random-bg
在.xinitrc-blackbox文件加入一行 300秒执行一次
watch -n 300 random-bg
参考
man: watch fbsetbg wmsetbg
http://vsbabu.org/mt/archives/20 ... ndom_wallpaper.html
http://moongroup.com/pipermail/s ... 02-June/007667.html |
|