【跟我学shell】每天换Bing壁纸
Tofloor
poster avatar
海天鹰
deepin
2018-05-19 19:23
Author
本帖最后由 sonichy 于 2018-5-20 10:01 编辑

隔壁小朋友用java写了个换 unsplash 壁纸,要搭建 java 环境,内存占用有点大,unsplash 网速慢。
哎,这么简单的工作为什么不要shell,shell 作为 Linux 的底层,有着无比的优越性。
只选对的,不选会的,虽然我对 shell 也不懂,但是我可以学啊。
Bing 壁纸的 API 我用了几年了,主要用于浏览器新标签页,一般好看的壁纸我才保存下来,设为壁纸,如果用shell自动设置壁纸,就不需要多几个步骤了。

#清屏
printf "\033c"
URL="https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"
domain=${URL%/*}
HTML=`mktemp`
wget -q $URL -O $HTML
#str=${`cat $HTML`//\ //_}
#str=${str//,//\ }
#空格替换为_
str=`cat $HTML | sed 's/ /_/g'`
#双引号替换为_
str=`cat $HTML | sed 's/"/_/g'`
#逗号替换为空格
str=`echo $str | sed 's/,/ /g'`
#echo $str
#按空格分割到数组
array=($str)
for var in ${array[@]}
do
        if [[ $var =~ "_url_:_" ]]
        then
                #截取_url_:_右边的字符串
                url=${var##*_url_:_}
                #截取_左边的字符串
                url=${domain}${url%%_}
                echo $url
                filename=${url##*/}
                echo $filename
                wget -q $url -O $filename
                path=$(pwd)"/"$filename
                echo $path               
                gsettings set org.gnome.desktop.background picture-uri file://$path
                sleep 1
                rm $path
                break
        fi
done

~/.config/autostart 的 desktop 运行 shell 失败,如何添加开机 shell ?
Reply Favorite View the author
All Replies
avatar
ax******er@126.com
deepin
2018-05-19 19:44
#1
求打包Flatpak,一键安装。
Reply View the author
avatar
BG7ZAG
deepin
2018-05-19 19:45
#2
小白看不懂最后一句话
Reply View the author
avatar
DeepinOS
deepin
2018-05-19 19:45
#3
给你一个大大的赞
Reply View the author
avatar
BG7ZAG
deepin
2018-05-19 19:47
#4
本帖最后由 hlbj105 于 2018-5-19 11:54 编辑

是这样放吗?

Reply View the author
avatar
caedmon
deepin
2018-05-19 23:26
#5
#按空格分割到数组
array=($str)

上面这句报错:Syntax error: "(" unexpected
Reply View the author
avatar
jianguo922
deepin
2018-05-20 00:19
#6
谢谢楼主分享
Reply View the author
avatar
y***0@163.com
deepin
2018-05-20 01:09
#7
论坛里有个必应壁纸一键设置的app
Reply View the author
avatar
nero28
deepin
2018-05-20 02:02
#8
社区有个老兄分享了几个G的图片,放到默认壁纸文件夹下,右键随便换。比加个软件似乎更方便
Reply View the author
avatar
lulinux
deepin
2018-05-20 02:05
#9
本帖最后由 lulinux 于 2018-5-19 18:26 编辑

这种必应壁纸切换的shell脚本github上有不少,我结合crontab用了一年了。
Reply View the author
avatar
kid_kid
deepin
2018-05-21 22:26
#10
隔壁小朋友来给大佬点个赞
Reply View the author
avatar
农夫
deepin
2018-05-22 07:39
#11
本帖最后由 superfamer 于 2018-5-21 23:43 编辑

不是有个必应缤纷壁纸么(bingnicewallpapers)
Reply View the author