Last active
September 8, 2024 20:11
-
-
Save Limych/1ebb913ab57a87ce512bb72a5dca1807 to your computer and use it in GitHub Desktop.
Rotate best Earth photos as desktop background on Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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