Register
It is currently Sun Dec 21, 2014 5:29 pm

NASA's "Astronomy Picture Of the Day" as desktop background


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Tue Feb 02, 2010 9:42 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
I run the following daily from my crontab to grab the NASA "Astronomy Picture Of the Day" and set it as my desktop background.
It should work is most *nix flavours and Cygwin on Winblows.

90% of the time the picture is in jpg format, however the other 10% it can be anything so this only worries about jpgs.

Run it once and set your desktop background to that picture and put it into cron, it should update most days. Linux will even pick up the change on the fly, Winblows won't but...well, you know

Code:
#!/bin/bash
#
# Changes my desktop pic each day
# David.Stringer@ticketmaster.co.uk
#
# desktop.sh
# Copyright (C) 2007-2010  David Stringer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#

# sets DEBUG=0 unless it's set to something already
# turns on logging if set to >0
# can be turned on in the parent environment like so;
# DEBUG=1 desktop.sh
DEBUG=${DEBUG:-0}

# location of pic and log
cd /home/david/scripts/desktop
LOGFILE=/home/david/scripts/logs/desktop.log

# this sort of function is normally sourced from my scripting library
# for now I have just embedded a tweaked version of it, which is why it's a bit wordy
function maylog { # writes to $LOGFILE if it can
  if [ "$DEBUG" -eq 0 ]
  then
    return 0
  fi
  if [ "$LOGFILE" != "" -a -w "$LOGFILE" -o -w "$(dirname $LOGFILE)" ]
  then
    local icount=$#
    local iloop
    for ((iloop=0; iloop < $icount; iloop++))
    do
      echo "$1" >> "$LOGFILE"
      shift 1
    done
  fi
}

maylog "Starting desktop.sh"
maylog "$(date)"

picname=`wget -q -O - http://antwrp.gsfc.nasa.gov/apod/astropix.html | grep '<IMG SRC="' | head -1 | awk -F\" '{ print $2 }' 2>>/dev/null`

maylog "  picname=$picname"

if echo $picname | egrep '.jpg' >/dev/null
then
  maylog "Grabbing $picname"
  wget -q -O downloaded.jpg http://antwrp.gsfc.nasa.gov/apod/$picname 2>>/dev/null
  mv -f downloaded.jpg desktop.jpg 2>>/dev/null
else
  maylog "No jpg today"
fi

maylog "Complete" " "



Just in posting here I see a few improvements I should make :)

DW


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP