Skip to content

Instantly share code, notes, and snippets.

@Limych
Last active September 8, 2024 20:11
Show Gist options
  • Save Limych/1ebb913ab57a87ce512bb72a5dca1807 to your computer and use it in GitHub Desktop.
Save Limych/1ebb913ab57a87ce512bb72a5dca1807 to your computer and use it in GitHub Desktop.
Rotate best Earth photos as desktop background on Ubuntu
#!/usr/bin/env bash
# Rotate best Earth photos as desktop background on Ubuntu.
#
# Just run this file via crontab. As example for every hour rotation:
# 0 * * * * $HOME/change_bg.sh
#
# Source: https://gist.github.com/Limych/1ebb913ab57a87ce512bb72a5dca1807
USER=$(whoami)
if [[ -z $DBUS_SESSION_BUS_ADDRESS ]]; then
while read -r sessionId; do
# so for each session id, grep the environment from /proc/id/environ for the dbus address
grepVarMatch=$(grep -z "^DBUS_SESSION_BUS_ADDRESS=" /proc/$sessionId/environ | tr -d '\0')
if [[ "$grepVarMatch" != "" ]]; then
# set the address as an envvar in the sudo env
export DBUS_SESSION_BUS_ADDRESS="${grepVarMatch#*=}"
break # if we found it, we don't need to look further
fi
done <<< "$(pgrep "gnome-session" -u "$USER")"
fi
gsettings reset org.gnome.desktop.background picture-options
curl -fs "https://www.reddit.com/r/earthporn.json" | jq '.data.children[] |.data.url' | grep -v "reddit.com" | shuf >
gsettings set org.gnome.desktop.background picture-uri "/home/$USER/wallpaper.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment