国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Ubuntu > 正文

Ubuntu 設(shè)定壁紙自動切換的shell腳本

2024-06-28 13:24:01
字體:
供稿:網(wǎng)友
Ubuntu 設(shè)定壁紙自動切換的shell腳本

升級到Ubuntu14.04后,感覺bug的確比12.04少多了。頂部任務(wù)欄支持半透明效果,所以整個桌面也看上去漂亮了很多。這樣的桌面也是值得瞎搗鼓一下的,想到換壁紙,但是沒找到設(shè)定動態(tài)更換壁紙的選項(xiàng),但手動修改配置文件的方法總是有的,本文的目的也在于此。(以下過程在Ubuntu14上進(jìn)行,未測試其他版本!)。

原理

右鍵桌面->更改桌面背景,如下圖所示,在右側(cè)縮略圖中帶有小鐘表圖標(biāo)的就表示為動態(tài)切換的壁紙:

系統(tǒng)是通過讀取這個文件來進(jìn)行動態(tài)壁紙切換的:

/usr/share/backgrounds/contest/trusty.xml

文件主要內(nèi)容如下:

<background>    <starttime>        <year>2014</year>        <month>09</month>        <day>21</day>        <hour>00</hour>        <minute>00</minute>        <second>00</second>    </starttime>    <static>        <duration>300</duration>        <file>/home/kyy/Wallpaper/1019236,106.jpg</file>    </static>    <transition>        <duration>3</duration>        <from>/home/kyy/Wallpaper/1019236,106.jpg</from>        <to>/home/kyy/Wallpaper/1019306,106.jpg</to>    </transition>    <static>        <duration>300</duration>        <file>/home/kyy/Wallpaper/1019306,106.jpg</file>    </static>    <transition>        <duration>3</duration>        <from>/home/kyy/Wallpaper/1019306,106.jpg</from>        <to>/home/kyy/Wallpaper/1082502,106.jpg</to>    </transition>        <static>......        </static>         <transition>......        </transition>        ......</background>

其中static標(biāo)簽內(nèi)file表示當(dāng)前圖像,duration表示當(dāng)前圖像顯示的持續(xù)時(shí)間

transition標(biāo)簽內(nèi)from和to分別表示不下一步在那兩個圖片之間切換,duration表示過渡時(shí)間

so,系統(tǒng)就是根據(jù)這個來進(jìn)行桌面壁紙動態(tài)切換的。不過沒切換一次圖像就需要寫大量代碼,我們肯定不會腦殘到自己手動去寫的,那么的,既然實(shí)在linux下,用shell腳本代替人工自然是最合適不過了

shell腳本實(shí)現(xiàn)
  1 #!/bin/bash  2   3 #可用文件后綴名列表  4 readonly PRefixs=("jpg" "jpeg" "png" "bmp")  5   6 #動態(tài)背景文件地址  7 #/usr/share/backgrounds/contest/trusty.xml  8 readonly animate_background_file_path="/usr/share/backgrounds/contest/trusty.xml"  9   10 #文件列表索引 11 index=0 12  13 #獲取圖像文件列表 14 get_image_files(){ 15      16     #獲取文件所在目錄名稱 17     base_dir="`dirname $1`/`basename $1`/" 18      19     for f in `ls $1` 20     do     21         #檢查文件后綴 22         for p in "${prefixs[@]}" 23         do 24             len_before=${#f} 25             f_after=${f%"$p"} 26             len_after=${#f_after} 27              28             #名稱發(fā)生改變,說明后綴名稱符合條件 29             if [ $len_before -ne $len_after ] 30             then 31                 file_list[$index]="$base_dir$f" 32                 echo "獲取圖像:$base_dir$f" 33                 let index=$index+1 34                 break 35             fi 36         done 37     done 38  39 } 40   41  42 #寫入文件 43 replae_file(){ 44  45     #創(chuàng)建臨時(shí)文件 46     animate_back="animate_back.xml" 47     #清空文本內(nèi)容 48     cat /dev/null > $animate_back 49      50     echo -e  "<background>" >> $animate_back 51     echo -e  "/t<starttime>" >> $animate_back 52     echo -e  "/t/t<year>$(date +%Y)</year>" >> $animate_back 53     echo -e  "/t/t<month>$(date +%m)</month>" >> $animate_back 54     echo -e  "/t/t<day>$(date +%d)</day>" >> $animate_back 55     echo -e  "/t/t<hour>00</hour>" >> $animate_back 56     echo -e  "/t/t<minute>00</minute>" >> $animate_back 57     echo -e  "/t/t<second>00</second>" >> $animate_back 58     echo -e  "/t</starttime>" >> $animate_back 59  60     #寫入文件名稱 61     index_=0 62     len=${#file_list[@]} 63     for f in "${file_list[@]}" 64     do     65         if [ $index_ -eq $((len-1)) ] 66         then 67             fn=${file_list[0]} 68         else 69             fn=${file_list[$index_+1]} 70         fi 71  72         echo -e  "/t<static>" >> $animate_back 73         echo -e  "/t/t<duration>${STAY:=300}</duration>" >> $animate_back 74         echo -e  "/t/t<file>$f</file>" >> $animate_back 75         echo -e  "/t</static>" >> $animate_back         76         echo -e  "/t<transition>" >> $animate_back 77         echo -e  "/t/t<duration>${DURATION:=3}</duration>" >> $animate_back 78         echo -e  "/t/t<from>$f</from>" >> $animate_back 79         echo -e  "/t/t<to>$fn</to>" >> $animate_back 80         echo -e  "/t</transition>" >> $animate_back 81          82         let index_=$index_+1 83     done 84          85     echo -e  "</background>" >> $animate_back 86      87     #移動文件 88     mv $animate_back $animate_background_file_path 89     if [ $? -eq 0 ]         90     then  91         echo -e  "已經(jīng)設(shè)定好文件" 92     fi 93  94 } 95  96 help(){ 97     echo 98     echo "命令格式:`basename $0` [OPTION] -f Filepath" 99     echo "指定圖片目錄,目錄下的圖片將作為動態(tài)更換的壁紙"100     echo101     echo -e "-f[Filepath]/t 圖像文件目錄"102     echo -e "-d[Duration]/t 圖像切換時(shí)長,默認(rèn)3s"103     echo -e "-s[StayTime]/t 圖像停留時(shí)長,默認(rèn)300s"104     echo105     exit 1106 }107 108 109 #處理參數(shù)110 while getopts f:s:d: OPTION111 do112     case "$OPTION" in113     f)114         FILE_PATH="$OPTARG"115         ;;116     s)117         STAY="$OPTARG"118         ;;119     d)120         DURATION="$OPTARG"121         ;;122     *)123         help124         ;;125     esac126 done127 128 if [ -z "$FILE_PATH" ]129 then  130     help    131 fi132 133 134  135 #判斷目錄是是否存在136 if [ -d $FILE_PATH ]137 then     138     #獲取到文件列表139     get_image_files $FILE_PATH140     141     #獲取文件數(shù)目142     file_count=${#file_list[@]}143     144     if [ $file_count -gt 0 ]        145     then146         #替換原有動態(tài)背景文件147         echo "共獲取到$file_count個圖像文件"148         replae_file     149     else150         echo "目錄$FILE_PATH下不存在符合要求的圖像文件:${prefixs[*]}"151     fi152     153 154 else155     echo "不存在目錄:$FILE_PATH"            156 fi                     157  158 159 exit 0


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 田阳县| 定日县| 沂水县| 巴林右旗| 阿城市| 张家口市| 峡江县| 肃南| 晋州市| 甘谷县| 綦江县| 介休市| 陈巴尔虎旗| 邢台市| 红安县| 宁城县| 三门峡市| 大方县| 桓仁| 蒙山县| 图们市| 井冈山市| 长丰县| 静宁县| 乌审旗| 辉南县| 黄山市| 基隆市| 桂东县| 博野县| 绥宁县| 通州市| 柏乡县| 永丰县| 山阴县| 图们市| 手机| 台中县| 湖州市| 北辰区| 密云县|