您的位置:首页 > 其它

ubuntu 动态桌面xml文件生成脚本

2010-09-22 17:09 351 查看

Ubuntu 动态桌面xml文件,生成脚本 (bash shell)

#!/bin/bash
#!/bin/bash
# ubuntu background.xml create
# 2010.09
# v 0.1
create_head ()
{

echo '<background>' >>$outfile
echo  '<starttime>' >>$outfile
echo '    <year>2010</year>' >>$outfile
echo '<month>09</month>' >>$outfile
echo '    <day>00</day>' >>$outfile
echo '    <hour>00</hour>' >>$outfile
echo '    <minute>00</minute>' >>$outfile
echo '   <second>00</second>' >>$outfile
echo '  </starttime>'  >>$outfile
echo ' <!--++++-->' >>$outfile
}
first=1
file_first=""
install_one ()
{
file_one=$1
if [ $first -eq 0  ];then
echo "   <to>$file_one</to>" >>$outfile
echo "</transition>" >>$outfile
else
first=0
file_first=$file_one
fi
echo "<static>" >>$outfile
echo "   <duration>$static</duration>" >>$outfile
echo "   <file>$file_one</file>" >>$outfile
echo "</static>" >>$outfile
echo "<transition>" >>$outfile
echo "   <duration>$delay</duration>" >>$outfile
echo "   <from>$file_one</from>" >>$outfile
}
isimage ()
{
file $1 | grep image &> /dev/null && return 0
return 1
}
dir ()
{
c_dir=`pwd`
cd $dir
dir=`pwd`
#echo $dir
for file in `ls $dir`
do
isimage $file &&  install_one $dir/$file
done
cd $c_dir
}
configfile ()
{
for file in `cat $configfile`
do
isimage $file && install_one $file
done
}
# ============================
# usage ======================
# ============================
usage ()
{
echo "Usage: -l , --delay        delay time (s) ,default is 3 s"
echo "       -s , --static       static time (s) ,default is 1800 s (30min)"
echo "       -d , --dir          Use the specified folder to create config file"
echo "                           for all files"
echo "       -c , --configfile   Specify a configuration file,it's a list of files"
}

[ -z "$*"  ] && {
usage
exit 2
}
outfile=/tmp/background.outfile
touch $outfile
echo >$outfile
delay=5
static=1800
while true
do
opt=`echo $* | cut -d' ' -f1`
shift 1
val=`echo $* | cut -d' ' -f1`
case $opt  in
-d|--dir)
[ -d "$val"  -a  -z "$configfile"  ] && dir=$val || {
echo  $opt Error
exit 1
};;
-l|--delay)
[ -n "$val"  ] && delay=$val || {
echo $opt Error
exit 1
};;
-s|--static)
[ -n "$val"  ] && static=$val || {
echo $opt Error
exit 1
};;
-c|--configfile)
[ -f "$val" -a -z "$dir"  ] && configfile=$val || {
echo $opt Error
exit 1
};;
-h|--help)
usage
exit 1;;
*)
if [ -n "$opt"  ];then
echo invalib option:$opt
echo "Try '`basename $0` -h/--help' for more information."
fi
break;;
esac
shift 1
done
create_head
if [ -n "$dir" ] ;then
dir
elif [ -n  "$configfile"  ] ;then
configfile
else
echo `basename $0`: Must use the option  -d / -c
exit 2
fi
echo "    <to>$file_first</to>" >>$outfile
echo "</transition>" >>$outfile
echo '</background>' >>$outfile
cat /tmp/background.outfile
echo ""
exit 0


脚本选项说明:

-l / --delay 两张壁纸切换的渐变时间,单位 秒, 默认3 秒

-s / --static 多长时间进行一次壁纸的切换,单位 秒 ,默认 1800 秒 /30 分钟

-d / --dir 指定一个目录,该目录下的所有图片文件,都将做为壁纸写入xml文件中

-c / --configfile 指定一个配置文件,该文件中含壁纸文件的完整路径,一行一个文件路径

补充说明:

1, -d 和-c选项不能同时使用

2, 。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: