搞几张壁纸,没事自动切换下,Gnome
2017-04-14 05:51:31
Fuck
  • 访问次数: 10
  • 注册日期: 2017-04-14
  • 最后登录: 2017-05-11
  • 当前积分: 102
#!/bin/bash

GBP="$HOME/.local/share/gnome-background-properties"
XML_FILE="$GBP/user-wallpapers.xml"

echo -n "请输入壁纸所在路径:"
read PICS_DIR

while [ ! -d $PICS_DIR ]
do
echo -n "请输入正确的路径:"
read PICS_DIR
done

n=`find $PICS_DIR -name "*.jpg" -o -name "*.png" | wc -l`
while [ $n -eq 0 ]
do
echo -n "请输入正确的包含“JPG”或“PNG”格式壁纸的路径:"
read PICS_DIR
n=`find $PICS_DIR -name "*.jpg" -o -name "*.png" | wc -l`
done

echo -n "壁纸图片自动切换时间(单位/秒):"
read TIME

expr $TIME + 10 &> /dev/null
until [ $? -eq 0 ]
do
echo -n "请输入有效的数字:"
read TIME
expr $TIME + 10 &> /dev/null
done

echo -n "是否立即生效?(yes/no)"
read WORKS

until [ x$WORKS != xyes ] || [ x$WORKS != xno ]
do
echo -n "Please type 'yes' or 'no':"
read WORKS
done

if [ ! -d $GBP ]; then
mkdir $GBP
fi

cat <<_EOF > $XML_FILE
<background>
<starttime>
<year>2016</year>
<month>11</month>
<day>15</day>
<hour>00</hour>
<minute>00</minute>
<second>00</second>
</starttime>
_EOF

find $PICS_DIR -name "*.jpg" -o -name "*.png" | while read line
do
cat <<_EOF >> $XML_FILE
<static>
<duration>$TIME</duration>
<file>$line</file>
</static>
_EOF
done

cat <<_EOF >> $XML_FILE
</background>
_EOF

if [ x"$WORKS" = xyes ]; then
gsettings set org.gnome.desktop.background picture-uri "$XML_FILE"
fi


Fuck 最后编辑, 2017-04-14 05:52:47