You are not logged in.
Pages: 1
Heyas
I'm using this in my AwesomeWM, and thought you guys might like this too
It consists of 2 scripts, one to change the background according to existing images, and the main script which searches the RSS of NASA's Image of the Day gallery.
The scripts are located in: $HOME/.config/awesome/scripts.
Since the nasaBackground.sh is executed upon graphical login, i wanted to have it look a bit more 'professional', so i've used TUI -> https://bbs.archlinux.org/viewtopic.php?id=197719
Preview: https://sea.fedorapeople.org/img/awesom … .01.28.jpg
AwesomeConfig: https://github.com/sri-arjuna/awesome-config
The fallbackscript, to change among already downloaded IOTD's or otherwise existing images to be used as wallpaper.
changebg.sh
#!/bin/bash
#
# Choose among default backgrounds
# or stored recent NASA backgrounds,
# or type in a custom background path.
#
# Author: Simon A. Erat (sea) <erat.simon AT gmail.com>
# Created (y.m.d): 2012.10.24
# Changed: 2015.03.08
# License: GPL v3
script_version=0.4
#
# Variables
#
# Requires TUI
defaultbg=$HOME/.config/awesome/img
nasabg=$HOME/.backgrounds
distrobg=/usr/share/backgrounds
opt="--bg-fill"
opt="--bg-scale"
oPWD="$PWD"
str_kind="Select kind of background:"
str_bg="Select the actual background image:"
#
# Outout
#
printf "\r\t\r" #;echo
sleep 0.04
tui-header "sea's Awesome WM" "Change BG"
tui-title "$str_kind"
style=menu
while [ ! "$style" = Back ]
do style=$(tui-select Back NASA-Random NASA Defaults Distro Custom)
[ ! Back = "$style" ] && tui-title "$style"
case "$style" in
Back) break ;;
NASA-Random) path=$nasabg
cd "$path"
max=$(ls -l|wc -l)
num=$(rnd $max)
files=( * )
img="${files[$num]}"
tui-echo "Selected random:" "$img"
cd "$oPWD"
;;
NASA) path=$nasabg ;;
Distro) path=$distrobg ;;
Defaults) path=$defaultbg ;;
Custom) path=$(input "Please type the absolute path of the images:") ;;
esac
case "$style" in
NASA-Random) feh $opt "$path/$img"
tui-echo
;;
*) tui-echo "$str_bg"
tui-echo "Images from path:" "$path"
pics=$(cd "$path";ls;cd "$oPWD")
img=todo
while [ ! Back = "$img" ]
do img=$(tui-select Back $pics)
[ $img = Back ] && break
feh $opt "$path/$img"
tui-status $? "Set background to: $img"
tui-echo
tui-title "$style"
tui-echo "$str_bg" "or go Back"
done
;;
esac
tui-title "$str_kind"
#tui-echo "$str_kind" "or go Back to exit."
done
The core script to download the latest IOTD:
nasaBackground.sh
#!/bin/bash
# grabs the nasa image of the day by RSS feed and updates the gnome
# background. add this to your cron jobs to have this happen daily. this is,
# obviously, a hack, that is likely to break at the slightest change of NASA's
# RSS implementation. yay standards!
#EDITED FOR feh
#EDITED FOR tui
#
# Variables
#
img_url=""
img_name=""
rss=""
RSS1="http://www.nasa.gov/rss/lg_image_of_the_day.rss"
RSS2="http://www.nasa.gov/rss/dyn/image_of_the_day.rss"
target=""
FOLDER="$HOME/.backgrounds"
#
# Display & Action
#
# TITLE
sleep 0.5
tui-title "NASA - Image of the Day"
tui-echo " " "This script is not related with NASA"
RET=-1
for R in "$RSS1" "$RSS2";do
# Get Raw data
tui-status -r 2 "Retrieving raw data ($R)..."
rss=$(wget -q -O - "$R")
[ ! -z "$rss" ]
if tui-status $? "Retrieved raw data"
then # It has data, but can it find a recent image?
img_url=$(echo $rss | grep -o '<enclosure [^>]*>' | grep -o 'http://[^\"]*')
[ ! -z "$img_url" ] && \
RET=0 && \
break
fi
done
# Prepare download
#img_url=$(echo $rss | grep -o '<enclosure [^>]*>' | grep -o 'http://[^\"]*')
# change existing bg if no url was found
if [ -z "$img_url" ] || [ 0 -ne $RET ]
then tui-status 1 "No URL could be identified, changing background to random image"
tui-wait 5s "Changing to random wallpaper"
sh $(dirname $0)/changebg.sh << EOF
2
1
EOF
tui-status $? "Changed wallpaper"
sleep 3 ; exit 1
else [ -d "$FOLDER" ] || mkdir -p "$FOLDER"
img_url=$(echo $img_url|awk '{print $1}')
tui-status $? "Found URL:" "$img_url"
img_name=$(echo "$img_url" | grep -o [^/]*\.\w*$ )
target="$(date +'%F')_${img_name/\?*/}"
target="${target:0:(-3)}jpg"
tui-status $? "Selected image:" "$img_name"
# Download the image
cd "$FOLDER"
if [ ! -f "$img_name" ] && [ ! -f "$target" ]
then # Requires to become downloaded
tui-download "$img_url"
# Rename to list in date order
mv "$img_name" "$target"
tui-status $? "Renamed to" "$target"
# Converting to fixed size jpeg to save storage space
tui-printf "Converting $img_name..." "$TUI_WORK"
convert "$target" -resize $(xrandr | awk '/\*/ {print $1}') "$target"
tui-status $? "Converted ${target##*/}"
fi
target="${target:0:(-3)}jpg"
# Set it as bg
feh --bg-scale "$target"
tui-status $? "Changed background to $target"
cd "$OLDPWD"
tui-wait 10s
exit 0
fi
sleep 1
Hope you like it, have fun
Offline
Pages: 1