写了一个脚本,生成gnome桌面背景slide模式所需的xml文件

gnome桌面可以添加一组图片,设定时间自动的更换,所需的只是一个xml文件,见

/usr/share/backgrounds/cosmos/background-1.xml

受此启发,自己写了一个生成xml文件的脚本,可以很方便地把一个文件夹下面的所有图片(jpeg,png)包括在这一组slides中。

生成xml文件之后,在“更变桌面背景"中选中这一个xml文件,就好了。

 

在下载频道上传了一份,不过我也没找到。

 

#!/bin/bash printusage(){ echo "Usage: $0 [-s static duration] [-t transfer duration] [-o output file] directory " echo " $0 -h" echo " -s: static duration, default 1600" echo " -t: transfer durtaion, default 5" echo " -o: output file, default stdout" echo " -h: display this info" echo " directory: the directory that contains the images" } # get options # -t transfer duration # -s static durtaion # -o output xml file, default stdout STATIC_DUR=1600.0 TRANS_DUR=5.0 OUT_XML= while getopts t:s:o:h opt ; do case "$opt" in t) TRANS_DUR=$OPTARG;; s) STATIC_DUR=$OPTARG;; o) OUT_XML=$OPTARG if [ -e $OUT_XML ] ; then echo "NOTICE: $2 exists in current directory." echo -n "Do you want to overwrite it? [y/n] " read ans case "$ans" in y | yes | Yes | YES | Y ) ;; *) echo "exit for existed output file" exit 2;; esac fi ;; h) printusage exit 1;; /?) echo "Usage: $0 [-s static duration] [-t transfer duration] [-o output file] directory " echo "use /"$0 -h/" for more details" exit 1;; esac done # shift the options away shift $(( OPTIND - 1)) # get main dir MAIN_DIR= if [ $# -ne 1 ] ; then echo "agrument /"directory/" needed!" printusage exit 1 elif [ ! -d $1 ] ; then echo "$1 is NOT a directory" printusage exit 1 else MAIN_DIR=$1 if [ $MAIN_DIR = "." ]; then MAIN_DIR=$(pwd) fi MAIN_DIR=${MAIN_DIR%/} fi # search image files FILELIST= echo "Searching image files in $MAIN_DIR :" for f in $( echo $MAIN_DIR/*); do if ( file $f | grep -q "JPEG" ) || ( file $f | grep -q "PNG") ; then echo $f FILELIST="$FILELIST $f" else echo "WARNING! file $f is not a image file, ignore it" fi done # ack by user echo echo -n "Is these files OK? [y/n] " read ans case "$ans" in y | Y | yes | Yes | YES ) ;; *) exit 3;; esac # function create_xml, to create xml script create_xml() { FIRST=$1 # the header echo "<background>" echo " <starttime>" echo " <year>2010</year>" echo " <month>08</month>" echo " <day>01</day>" echo " <hour>00</hour>" echo " <minute>00</minute>" echo " <second>00</second>" echo " </starttime>" echo # the main body until [ $# -le 1 ]; do echo " <static>" echo " <duration>$STATIC_DUR</duration>" echo " <file>$1</file>" echo " </static>" echo " <transition>" echo " <duration>$TRANS_DUR</duration>" echo " <from>$1</from>" shift echo " <to>$1</to>" echo " </transition>" done; echo " <static>" echo " <duration>$STATIC_DUR</duration>" echo " <file>$1</file>" echo " </static>" echo " <transition>" echo " <duration>$TRANS_DUR</duration>" echo " <from>$1</from>" shift echo " <to>$FIRST</to>" echo " </transition>" echo # the end echo "</background>" } if [ -z "$OUT_XML" ]; then echo "dump the xml script on the screen:" echo create_xml $FILELIST else echo "create xml script file $OUT_XML." create_xml $FILELIST > $OUT_XML fi exit

 

你可能感兴趣的:(写了一个脚本,生成gnome桌面背景slide模式所需的xml文件)