2011年4月9日 星期六

ubuntu 10.04 自動更換桌布方式

原文

更新版本啦!
改進演算法,讓速度可以更快一點。
小弟用三萬個模擬檔測試,大概快了五倍以上吧。
用法沒變,只要將蒐集來的圖檔放在某個目錄中(需要兩個以上),
並且在同一個目錄下放一個文字檔(內容在最下面),
檔案的屬性設定為可執行,然後滑鼠點兩下要求執行它
同一個目錄裡面會出現一個 background.xml。
然後再到/系統/偏好設定/外觀/背景 下方按下加入的按鈕,
選擇加入新做出來的 background.xml 就可以了。

在內容的前幾行中,
outfil 設定檔案名稱;
statc 設定每張圖片顯示的秒數;
trans 則是畫面變換的秒數;
filtyp 可以設定支援的檔案類型,
這些都可以自己直接改。
如果 statc + trans 剛好等於 3600 的因數或倍數,
就會在某些或每個整點換桌布。

bkgndxml
- - - - 8< - - - - - - - - - - 請自本虛線下方剪下 - - - - - - - - - - - - - - -

#!/bin/bash

outfil=background.xml
statc=1795.0
trans=5.0
filtyp="*.gif *.GIF *.jpg *.JPG *.png *.PNG *.bmp *.BMP"

ls $filtyp 1> tmpfl6395671 2> /dev/null
filtol=$(wc -l tmpfl6395671 | cut -d " " -f1)
sed 's/ /jTqd-_u/g' tmpfl6395671 > tmpfl639567
rm -f tmpfl6395671


if [ $filtol -gt 1 ] ; then
for img in $(cat tmpfl639567)
do

if [ -z $previous ] ; then
first=$img
echo "" > $outfil
echo " " >> $outfil
echo " 2009" >> $outfil
echo " 08" >> $outfil
echo " 04" >> $outfil
echo " 00" >> $outfil
echo " 00" >> $outfil
echo " 00" >> $outfil
echo "
" >> $outfil
echo "" >> $outfil
echo " " >> $outfil
echo " "$statc"" >> $outfil
echo " "$PWD"/"$img"" >> $outfil
echo "
" >> $outfil
fi

if [ $previous ] ; then
echo " " >> $outfil
echo " "$trans"" >> $outfil
echo " "$PWD"/"$previous"" >> $outfil
echo " "$PWD"/"$img"" >> $outfil
echo "
" >> $outfil
echo " " >> $outfil
echo " "$statc"" >> $outfil
echo " "$PWD"/"$img"" >> $outfil
echo "
" >> $outfil
fi

previous=$img

done

echo " " >> $outfil
echo " "$trans"" >> $outfil
echo " "$PWD"/"$img"" >> $outfil
echo " "$PWD"/"$first"" >> $outfil
echo "
" >> $outfil
echo "
" >> $outfil

mv $outfil a$outfil
sed 's/jTqd-_u/ /g' a$outfil > $outfil
rm -f a$outfil

fi

unset outfil statc trans filtyp filtol img first previous
rm -f tmpfl639567


- - - - - - - - - - - - - - - - - - - - - - - - >8 - - - - - - - - - - - - - -
2010/02/21 更正:
filtyp="*.gif *.GIF *.jpg *.JPG *.png *.PNG *.bmp *.BMP"
原本忘記支援大寫附檔名,現在補上

沒有留言:

張貼留言