APOD Wallpaper in Gnome

APOD(Astronomy Picture of the Day)在Windows下面很多人将其作为每日的桌面,因此我尝试寻找方法在Linux下面实现这一功能,网络上已经有人实现过这一脚本,不过那是给KDE使用的,我经常使用的是Gnome,因此,修改修改就可以使用了。

原始文件: http://www.badgerpile.com/getAstronomyPicOfDay.sh

修改后我的文件: getAstronomyPicOfDay.sh

程序:

#!/bin/bash
# This program goes to a website, downloads an updated 'daily' picture
#  and sets your KDE background to that picture.
# Author: Luke Pahler
#  Many thanks to NASA/contributors for maintaining this 
#  killer webpage: http://antwrp.gsfc.nasa.gov/apod/archivepix.html

# Date Pattern: YYMMDD

#Calculate the URL to visit
# http://antwrp.gsfc.nasa.gov/apod/ap-=DATEVARIABLE=-.html
magicDate=`date +%y%m%d`

# Might as well store these pics in a tmp dir
#mkdir -p /tmp/astronomyPicOfDay/${magicDate}
#cd /tmp/astronomyPicOfDay/${magicDate}
mkdir -p /tmp/apod/${magicDate}
cd /tmp/apod/${magicDate}

#urlToVisit=http://antwrp.gsfc.nasa.gov/apod/ap${magicDate}.html
urlToVisit=http://antwrp.gsfc.nasa.gov/apod/astropix.html
echo I plan on visiting this URL: ${urlToVisit}

#Download the jpg from the page
wget -r -nd -np -l1 -A '*.jpg,*.jpeg,*.gif' ${urlToVisit} &> /dev/null
# now you have the thumbnail and the large linked to one
# *note gifs aren't animated, but still display

#Get the image to use
# fancy ls to get the largest file
bgImage=`ls --sort=size | head -n 1`
bgImageFullPath=`pwd`/${bgImage}
echo I plan on using this image: ${bgImageFullPath}

#Set your background to it (learnkde.txt)
#KDE
#dcop --user `whoami` kdesktop KBackgroundIface setWallpaper ${bgImageFullPath} 5

#Gnome
gconftool-2 -t string -s /desktop/gnome/background/picture_filename ${bgImageFullPath}

APOD大约每天下午4-5点更新,因此可以使用cron来完成这一工作。

$crontab -e 

加上2行,让其每日17:30和18:30各运行一次:

 30 17 * * * /home/hebl/bin/getAstronomyPicOfDay.sh > /dev/null &
 30 18 * * * /home/hebl/bin/getAstronomyPicOfDay.sh > /dev/null &

也可以在每次开机的时候运行它:系统->首选现->会话:中添加这条命令,并选择启动即可