自动下载bing当日墙纸,并改变为gnome桌面壁纸

写了一个手动白嫖当时bing的当日壁纸,并将其改变为gnome的壁纸,还是学到蛮多东东的

下一步的问题是加入到开机自启动项,使得开机后可以自动更新,目前已看到几篇博客

当然,也写了一个脚本使得可以恢复为默认的原来的壁纸

#!/bin/bash
PICTURE_REPO=~/CNSS/unix_homework/Pictures/bing_wallpapers/
echo "${PICTURE_REPO}"
mkdir -p "${PICTURE_REPO}"

PIC_FILE=$(date +U_Bing_bg_%Y_%m_%d.jpg)
BING_URL="https://www.bing.com"
BING_HTML="BingWeb.html"

# echo "$PIC_URL"
# echo "$PIC_FILE"
 
wget "${BING_URL}" -O "${BING_HTML}"
PIC_URL=$(grep -Po '(?<=href=")[^"]*jpg[^"]*' ./${BING_HTML})

echo "${PICTURE_REPO}${PIC_FILE}"
echo "Wanna Download picture to this destination?>"
read OPT
case $OPT in
    y|yes|YES|Y) ;;
    n|no|NO|N) exit 0
        ;;
esac

wget "${BING_URL}$PIC_URL" -O "${PICTURE_REPO}${PIC_FILE}"
rm -i "$BING_HTML"

if [ -e "orgin_bg" ]; then
    echo "orgin_bg has existed"
else
    gsettings get org.gnome.desktop.background picture-uri > ./orgin_bg
fi

PIC_DIR="file://${PICTURE_REPO}${PIC_FILE}"

echo $PIC_DIR
echo "Wanna Change ur background?>"
read OPT
case $OPT in
    y|yes|YES|Y) ;;
    n|no|NO|N) exit 0
        ;;
esac

gsettings set org.gnome.desktop.background picture-uri "$PIC_DIR"

这里是回复为原先默认桌面的脚本

#!/bin/bash
if [ ! -e orgin_bg ]; then
    echo "orgin_bg file doesn't exist"
    exit 2
fi

ORG_PI=$(cat orgin_bg)
echo "$ORG_PIC"
echo "Wanna recover?[y/n]>"
read OPT

case $OPT in
    y|yes|YES|Y) ;;
    n|no|NO|N) exit 1
        ;;
esac

gsettings set org.gnome.desktop.background picture-uri $ORG_PIC

猜你喜欢

转载自www.cnblogs.com/Idi0t-N3/p/12682089.html
今日推荐