Ubuntu 12.04自动切换桌面背景


Ubuntu 12.04自动切换桌面背景
 
以前在gnome2时使用gconftool可以改变ubuntu的桌面背景的,装了12.04后,发现不行了,研究了一下,原来改用gsettings这个工具了.
 
我卸载了unity,装的是gnome-panel桌面.
 
脚本如下:
 
[cpp] 
#!/bin/bash  
confFile=".switchbg.conf"  
cd $(dirname $0)  
filepath=$PWD  
find $filepath | grep -E ".jpg$|.png$|.JPG$|.PNG$" > $confFile  
cnt=`cat $confFile | wc -l`  
  
while true  
do  
line=$(($RANDOM % $cnt + 1))  
bgfile=$(head -n $line $confFile | tail -n 1)  
bgfile="'file://$bgfile'"  
bkfile=$(gsettings get org.gnome.desktop.background picture-uri)  
echo $bkfile  
echo $bgfile  
if [ $bkfile != $bgfile ]  
then  
break  
fi  
done  
gsettings set org.gnome.desktop.background picture-uri $bgfile  
rm -f $confFile  
保存后加到crontab里发现脚本的gsettings set不起作用.所以只能改一下了:
 
[cpp] 
#!/bin/bash  
confFile=".switchbg.conf"  
changedtime=600  
cd $(dirname $0)  
filepath=$PWD  
find $filepath | grep -E ".jpg$|.png$|.JPG$|.PNG$" > $confFile  
cnt=`cat $confFile | wc -l`  
while true  
do  
while true  
do  
line=$(($RANDOM % $cnt + 1))  
bgfile=$(head -n $line $confFile | tail -n 1)  
bgfile="'file://$bgfile'"  
bkfile=$(gsettings get org.gnome.desktop.background picture-uri)  
if [ $bkfile != $bgfile ]  
then  
break  
fi  
done  
gsettings set org.gnome.desktop.background picture-uri $bgfile >> tmp.log  
sleep $changedtime  
done  
rm -f $confFile  
让脚本在启动时自动加载就好了.间隔时间修改changedtime的值就行了,单位为秒.
 

相关内容

    暂无相关文章