diff --git a/apod.sh b/apod.sh index 9709fb7..e282049 100755 --- a/apod.sh +++ b/apod.sh @@ -1,15 +1,34 @@ #!/bin/bash + +# TO DEBUG: +set -x +env + +export DISPLAY=:1 +export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus" + +WALLPAPERS_DIR=/usr/local/google/home/pisquared/Pictures/wallpapers NASA_APOD_BASE_URL="https://apod.nasa.gov/apod" IMAGE_URL=`curl -s $NASA_APOD_BASE_URL/astropix.html | grep -oh 'href="image/.*"' | grep -oh 'image/.*jpg' | head -1` -if [ -z "$IMAGE_URL" ]; then - # gsettings set org.gnome.desktop.background picture-uri "file:///home/pi2/Pictures/wallpapers/blue_galaxy_wallpaper.png" - # xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitoreDP-1/workspace0/last-image --set /home/pi2/Pictures/wallpapers/blue_galaxy_wallpaper.png - # xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitorHDMI-2/workspace0/last-image --set /home/pi2/Pictures/wallpapers/blue_galaxy_wallpaper.png - feh --randomize --bg-fill /home/pi2/Pictures/wallpapers/* +if [ "$1" == "r" ] || [ -z "$IMAGE_URL" ]; then + IMG=$(ls $WALLPAPERS_DIR | sort -R | tail -1) else - curl -s "$NASA_APOD_BASE_URL/$IMAGE_URL" > image.jpg - # gsettings set org.gnome.desktop.background picture-uri "file:///$(pwd)/image.jpg" - # xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitoreDP-1/workspace0/last-image --set "$(pwd)/image.jpg" - # xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitorHDMI-2/workspace0/last-image --set "$(pwd)/image.jpg" - feh --bg-fill "$(pwd)/image.jpg" + IMG="image-$(date --iso).jpg" + if [ ! -f $WALLPAPERS_DIR/$IMG ]; then + curl -s "$NASA_APOD_BASE_URL/$IMAGE_URL" > $WALLPAPERS_DIR/$IMG + fi fi + +# OPTIONS DEPENDING ON ENV +# - for cinnamon +gsettings set org.cinnamon.desktop.background picture-uri "file://$WALLPAPERS_DIR/$IMG" + +# - for gnome +#gsettings set org.gnome.desktop.background picture-uri "file://$WALLPAPERS_DIR/$IMG" + +# - for i3 +# feh --bg-fill "$(pwd)/image.jpg" + +# - for XFCE (modify the displays names, e.g. to view them - run xrandr) +# xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitoreDP-1/workspace0/last-image --set "$WALLPAPERS_DIR/$IMG" +# xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitorHDMI-2/workspace0/last-image --set "$WALLPAPERS_DIR/$IMG" diff --git a/crontab b/crontab index c74c6c1..c6280a1 100644 --- a/crontab +++ b/crontab @@ -1,2 +1,2 @@ -0 * * * * export DISPLAY=:0 && cd $HOME/workspace/apod-wallpaper && ./apod.sh -@reboot export DISPLAY=:0 && cd $HOME/workspace/apod-wallpaper && ./apod.sh +0 * * * * cd $HOME/workspace/apod-wallpaper && ./apod.sh +@reboot cd $HOME/workspace/apod-wallpaper && ./apod.sh