James Blogs

复制以下代码保存文件为bing-background.sh

#!/bin/bash
cachePath=/home/jiy/.cache/bing-background
mkdir -p $cachePath
url=$(http <http://cn.bing.com> | grep -o "g_img.*.jpg\\"" | awk -F '\\"' '{print $2}' | xargs -i echo <https://cn.bing.com>{})
filename=$(echo $url | grep -oE "[0-9a-zA-Z_\\-]+\\.jpg")
curl $url -o $cachePath/$filename
gsettings set org.gnome.desktop.background draw-background false
gsettings set org.gnome.desktop.background picture-uri 'file://'$cachePath/$filename
gsettings set org.gnome.desktop.background picture-options scaled
gsettings set org.gnome.desktop.background primary-color FFFFFF
gsettings set org.gnome.desktop.background draw-background true

设置每天9点自动更新桌面,输入:

crontab -e

新建一行加入以下内容:

0 9 * * * /文件路径/bing-background.sh