写了一个脚本,生成gnome桌面背景slide模式所需的xml文件
2010-10-23 12:02
513 查看
gnome桌面可以添加一组图片,设定时间自动的更换,所需的只是一个xml文件,见
/usr/share/backgrounds/cosmos/background-1.xml
受此启发,自己写了一个生成xml文件的脚本,可以很方便地把一个文件夹下面的所有图片(jpeg,png)包括在这一组slides中。
生成xml文件之后,在“更变桌面背景"中选中这一个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
相关文章推荐
- Hibernate使用自定义脚本替换注解或者xml文件中的自动生成表结构
- 用SQL语句生成某个库下所有存储过程脚本,并每个存为一个文件
- Java读取一个xml文件并生成相应的类
- 一个生成文件固定格式的简单shell脚本
- 一个python 脚本将XML文件转换到excel
- 用python生成一个导出数据库的bat脚本文件
- 得用SQL语句生成某个库下所有存储过程脚本,并每个存为一个文件
- 利用python生成一个导出数据库的bat脚本文件
- 生成一个xml文件
- Bash:如何不用写脚本的情况下建立一个目录,然后在其中生成一组有规律的文件.
- ubuntu / Mint下 perl 实现动态桌面壁纸 生成xml的实用脚本
- XML 生成一个XML文件
- 生成一个XML文件:XML的序列化器
- [iOS开发]如何用KissXML生成一个XML文件
- Eclipse新建Servlet出错;生成UTF-8的编码的JSP;.xml文件大小设置,eclipse背景颜色设置
- PHP DOM创建生成一个XML文件
- 脚本文件中使用变量(得到当前时间,用来生成一个文件夹)
- android编译时生成了一个 main.out.xml文件,无法编译的解决办法
- 一个序列化器,满足多个xml文件生成
- 一个模拟页面操作,解析xml输出,生成CSV文件的ruby程­序