[转]bing壁纸天天换 初识shell魅力
原文链接:http://www.cnblogs.com/atskyline/p/3679522.html
原文的程序跑在window上,curl的使用不太一样,想要获取的图片也不太一样。修改后的代码如下:
#!/bin/bash # export DBUS_SESSION_BUS_ADDRESS environment variable useful when the script is set as a cron job
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-) # $bing is needed to form the fully qualified URL for
# the Bing pic of the day
bing="cn.bing.com" # $xmlURL is needed to get the xml data from which
# the relative URL for the Bing pic of the day is extracted
#
# The mkt parameter determines which Bing market you would like to
# obtain your images from.
# Valid values are: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA.
#
# The idx parameter determines where to start from. 0 is the current day,
# 1 the previous day, etc.
xmlURL="-d 'format=xml&idx=0&n=1&mkt=zh-CN' --get http://cn.bing.com/HPImageArchive.aspx" # $saveDir is used to set the location where Bing pics of the day
# are stored. $HOME holds the path of the current user's home directory
saveDir="$HOME/Pictures/Bing/" # Create saveDir if it does not already exist
mkdir -p $saveDir # Set picture options
# Valid options are: none,wallpaper,centered,scaled,stretched,zoom,spanned
picOpts="zoom" # The desired Bing picture resolution to download
# Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200"
desiredPicRes="_1920x1200" # The file extension for the Bing pic
picExt=".jpg" # Extract the relative URL of the Bing pic of the day from
# the XML data retrieved from xmlURL, form the fully qualified
# URL for the pic of the day, and store it in $picURL # Form the URL for the desired pic resolution
desiredPicURL=$bing$(echo $(curl $xmlURL) | grep -oP "<urlBase>(.*)</urlBase>" | cut -d ">" -f 2 | cut -d "<" -f 1)$desiredPicRes$picExt # Form the URL for the default pic resolution
defaultPicURL=$bing$(echo $(curl $xmlURL) | grep -oP "<url>(.*)</url>" | cut -d ">" -f 2 | cut -d "<" -f 1) # $picName contains the filename of the Bing pic of the day # Attempt to download the desired image resolution. If it doesn't
# exist then download the default image resolution
if wget --quiet --spider "$desiredPicURL"
then # Set picName to the desired picName
picName=${desiredPicURL##*/}
# Download the Bing pic of the day at desired resolution
curl -s -o $saveDir$picName $desiredPicURL
else
# Set picName to the default picName
picName=${defaultPicURL##*/}
# Download the Bing pic of the day at default resolution
curl -s -o $saveDir$picName $defaultPicURL
fi # Set the GNOME3 wallpaper
gsettings set org.gnome.desktop.background picture-uri "file://$saveDir$picName" # Set the GNOME 3 wallpaper picture options
gsettings set org.gnome.desktop.background picture-options $picOpts # Remove pictures older than 30 days
#find $saveDir -atime 30 -delete # Exit the script
exit
然后用crontab,做成每日任务,就可以天天换bing壁纸了。crontab代码如下:
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# m h dom mon dow command
15 1 * * * /home/kuizhi/program/bingWallPaper.sh
[转]bing壁纸天天换 初识shell魅力的更多相关文章
- 【壁纸自动换】自动下载、更换壁纸(Bing壁纸)--XinBSBingWallPaper[2.7更新]
XinBSBingWallPaper主要功能: 1.支持自动下载Bing壁纸.Netbian壁纸.美国国家地理杂志图片. 2.自动搜索.下载多国Bing首页壁纸. 3.支持定时自动更换桌面壁纸. 4. ...
- 初识Shell与Shell脚本
初识Shell Shell 是一个用 C 语言编写的程序,Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内 ...
- Linux基础入门(一)初识Shell
Linux基础入门(一)初识Shell shell是什么 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言. Shell ...
- 我们一起来学Shell - 初识shell
文章目录 Shell 的分类 `bash` `csh` `ksh` `tcsh` `sh` `nologin` `zsh` Shell 能做什么 bash 环境变量文件 `/etc/profile` ...
- Ubuntu 设定壁纸自动切换的shell脚本
升级到Ubuntu14.04后,感觉bug的确比12.04少多了.顶部任务栏支持半透明效果,所以整个桌面也看上去漂亮了很多.这样的桌面也是值得瞎捣鼓一下的,想到换壁纸,但是没找到设定动态更换壁纸的选项 ...
- window10自动更换bing壁纸
问题描述: bing的每日推荐的首页壁纸很不错,想当做系统壁纸! https://cn.bing.com/ 问题解决: 在window-store商店搜索 “Dynamic Theme”,安装即可! ...
- 自动同步bing壁纸
在百度搜东西,经常出来一大坨广告:要么就是复制粘贴文章.完全没有创新,搜索越来越困难.偶尔用一下bing还挺好用. bing的壁纸是真心好看,每天不重样.决定写个脚本同步一下它的壁纸. 一.以我的Wi ...
- 1.初识Shell脚本语言
PS:在做Linux下STM8固件升级项目中,需要让CPU通过I2C总线给STM8传输数据,刚开始一个一个的敲,很浪费时间,用shell脚本大大提高了数据传输效率,它是用户与内核进行交互操作的一种接口 ...
- bing壁纸xml地址
http://www.bing.com/gallery/?src=livesino# http://www.bing.com/HPImageArchive.aspx?format=xml&id ...
随机推荐
- python全局变量被覆盖的问题
下面的情况,foo全局变量会被局部变量覆盖掉,这样在其它地方使用的值就是空值. g_foo = '' #全局变量 def set(): g_foo = 'abc' # 给全局变量赋值 def use_ ...
- 转:GitHub 万星推荐成长技术清单
转:http://www.4hou.com/info/news/7061.html 最近两天,在reddit安全板块和Twitter上有个GitHub项目很火,叫“Awesome Hacking”. ...
- CodeForces 723E One-Way Reform
构造. 有一种十分巧妙的方法可以使图中所有度数为偶数的节点,经过每条边定向后,出度和入度都相等. 首先统计每个节点的度数,将度数为奇数的节点与编号为$n+1$的节点连边,这样一来,这张新图变成了每个节 ...
- Jenkins实现CI(Continuous Integration)到CD(Continuous Delivery)
Pipeline as Code是2.0的精髓所在,是帮助Jenkins实现CI(Continuous Integration)到CD(Continuous Delivery)华丽转身的关键推手.所谓 ...
- 【BZOJ 2124】【CodeVS 1283】等差子序列
http://www.lydsy.com/JudgeOnline/problem.php?id=2124 http://codevs.cn/problem/1283/ 重点是把判断是否存在3个数组成等 ...
- [BZOJ5267]特工
一个套路题...但还是得写一下这个套路避免以后忘了 题目中的运算$f(i,j)=(i|j)\text^i$对单位二进制满足$f(0,0)=f(1,0)=f(1,1)=1,f(0,1)=0$ 先考虑求正 ...
- Problem H: 零起点学算法109——单数变复数
#include <stdio.h> #include<string.h> int main(void) { int n; ]; scanf("%d",&a ...
- JAVA EE 中之AJAX 无刷新地区下拉列表三级联动
JSP页面 <html> <head> <meta http-equiv="Content-Type" content="text/html ...
- JavaScript基础入门教程(五)
说明 本系列博客的第一篇已经说明了,要求阅读者需要具有其它语言的编程基础,所以关于组数的基础部分本篇博客将不再赘述,主要讲js中数组的特性. 创建数组 数组的创建主要有两种方法,一种是数组直接量,还有 ...
- python的globals()使用
使用命令pyrasite-shell pid,可以与进程进行shell交互,获取,在shell里执行globals(),可以获取整个进程的全部全局变量,比如django应用.flask应用的变量,而不 ...