apod-wallpaper/apod.sh

37 lines
1.2 KiB
Bash
Raw Normal View History

2017-10-09 10:04:34 +02:00
#!/bin/bash
2022-04-29 16:39:41 +02:00
# TO DEBUG:
set -x
env
2024-09-07 16:06:59 +02:00
export DISPLAY=:0.0
2022-04-29 16:39:41 +02:00
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
2024-09-07 16:06:59 +02:00
WALLPAPERS_DIR=/home/pi2/Pictures/wallpapers
mkdir -p $WALLPAPERS_DIR
2017-10-09 10:04:34 +02:00
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`
2022-04-29 16:39:41 +02:00
if [ "$1" == "r" ] || [ -z "$IMAGE_URL" ]; then
IMG=$(ls $WALLPAPERS_DIR | sort -R | tail -1)
2017-12-13 15:45:44 +01:00
else
2022-04-29 16:39:41 +02:00
IMG="image-$(date --iso).jpg"
if [ ! -f $WALLPAPERS_DIR/$IMG ]; then
curl -s "$NASA_APOD_BASE_URL/$IMAGE_URL" > $WALLPAPERS_DIR/$IMG
fi
2017-12-13 15:45:44 +01:00
fi
2022-04-29 16:39:41 +02:00
# OPTIONS DEPENDING ON ENV
# - for cinnamon
2024-09-07 16:06:59 +02:00
#gsettings set org.cinnamon.desktop.background picture-uri "file://$WALLPAPERS_DIR/$IMG"
2022-04-29 16:39:41 +02:00
# - 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)
2024-09-07 16:06:59 +02:00
for MONITOR in $(xrandr --listmonitors | tail +2 | cut -d' ' -f6); do
xfconf-query --channel xfce4-desktop --property "/backdrop/screen0/monitor${MONITOR}/workspace0/last-image" --set "$WALLPAPERS_DIR/$IMG"
done