DEV Community

Cover image for How to have an updated desktop background from NASA's pictures
Jorge
Jorge

Posted on

How to have an updated desktop background from NASA's pictures

NASA has a website (https://apod.nasa.gov/apod/astropix.html) where publishs every day an astronomy picture plus a brief description

I have this url in my bookmark and usually I use the picture to change my Desktop background (they have a lot of great pictures) so I decided to have a cron to change it automatically but after a while I realized that most of the time I didn't know what I was watching so I included the explanation in the picture and now this is how my desktop looks

venus

Script

I use a little groovy script to download the json where the url and the explanation are and after downloaded the image I "inject" the explation into it in several lines (as the explanation can be large I take only a few hundreds of chars and split them)

as you can see the script perform this actions:

  • parse the current JSON directly from NASA's website
  • check if the picture is a valid extension (from time to time it's a video)
  • download the image into a Graphics
  • split the 300 first chars of the explanation into 3 String
  • paint every string at the top of the picture
  • save the picture as $HOME/Pictures/nasa.jpg

Cron

I use crontab to run this script every hour:

crontab -e

0 * * * * JAVA_HOME=$HOME/.sdkman/candidates/java/current $HOME/.sdkman/candidates/groovy/current/bin/groovy $HOME/nasa.groovy 
Enter fullscreen mode Exit fullscreen mode

but you can use others approach, for example as an startup program

Desktop settings

Now it only remains to change my Desktop background as $HOME/Pictures/nasa.jpg and when the NASA update the picture of the day I'll have my desktop updated

Top comments (0)