Skip to content

Instantly share code, notes, and snippets.

@mx-moth
Last active December 28, 2015 22:49
Show Gist options
  • Save mx-moth/7574249 to your computer and use it in GitHub Desktop.
Save mx-moth/7574249 to your computer and use it in GitHub Desktop.
Set your desktop background to the latest image from NASAs Solar Dynamics Observatory.
# The images from the SDO are updated every 15 minutes, so this script should only be run every 15 minutes.
DISPLAY=:0
4-59/15 * * * * $HOME/sdo-update --silent --type "0171" --screen "screen0/monitor0"
5-59/15 * * * * $HOME/sdo-update --silent --type "0193" --screen "screen0/monitor1"
#!/bin/bash
opts=$( getopt -o 'stxo' -l 'type:,size:,out:,screen:,silent' -n "${0}" -- "$@" )
if [ $? != 0 ] ; then exit 1 ; fi
eval set -- "$opts"
# Check out http://sdo.gsfc.nasa.gov/data/ for the different types and sizes.
SDO_SIZE="2048"
SDO_TYPE="0171"
# Images will be saved here
SDO_DIR="$HOME/Pictures/SDO"
# Select the screen/monitor you want to update
XCONF_SCREEN="screen0/monitor0"
LOG_LEVEL=1
while true ; do case "$1" in
-s|--silent) LOG_LEVEL=$(( $LOG_LEVEL - 1 )) ; shift ;;
-t|--type) SDO_TYPE="$2" ; shift 2 ;;
-x|--size) SDO_SIZE="$2" ; shift 2 ;;
-o|--out) SDO_DIR="$2" ; shift 2 ;;
--screen) XCONF_SCREEN="$2" ; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error! $1" >&2 ; exit 1 ;;
esac ; done
log() {
level="$1"
shift
if [ "$level" -le "$LOG_LEVEL" ] ; then
echo "$@"
fi
}
if [ "$LOG_LEVEL" -eq 0 ] ; then
CURL="curl -s"
else
CURL="curl -#"
fi
CURL="${CURL} -C -"
IMAGE_SRC="http://sdo.gsfc.nasa.gov/assets/img/latest/latest_${SDO_SIZE}_${SDO_TYPE}.jpg"
IMAGE_DST="${SDO_DIR}/$( date '+%Y/%m/%d/%H%M' )_${SDO_SIZE}_${SDO_TYPE}.jpg"
# Download the image
log 1 "${IMAGE_DST}"
mkdir -p "$( dirname "$IMAGE_DST" )"
$CURL -o "${IMAGE_DST}" -- "${IMAGE_SRC}"
# Set it as the desktop. If you use something other than xfce, you will need to change this.
xfconf-query \
--channel xfce4-desktop \
--property "/backdrop/${XCONF_SCREEN}/image-path" \
--set "${IMAGE_DST}"
@eval-apply
Copy link

;; quick and dirty elisp version
(require 'cl)

(defun* sun-as-desktop (&key (size 2048) (type 0171) (path "/tmp/"))
  (let* ((base-url "http://sdo.gsfc.nasa.gov/assets/img/latest/latest_")
         (filename (format "%s_0%s.jpg" size type))
         (outfile (concat path (format-time-string "%Y%m%d%H%M" (current-time)) "_" filename)))
    (if (not (file-exists-p path))
        (make-directory path))
    (url-copy-file (concat base-url filename) outfile t)
    (shell-command-to-string (concat "feh --bg-center " outfile))))

(sun-as-desktop :path "~/backgrounds/")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment