Change GNOME3 background randomly
calendar Aug. 30, 2015   category  bash , scripting , gnome-shell   comments  comments


So here's something. Changing background image randomly. Shouldn't be that hard, eh, GNOME?

Yes, there's gsettings. But making it user-friendly should be a priority as well. So here's a small script that does that:

 

#!/bin/bash
#
# Change GNOME3 background randomly
#
# Léon Keijser - leon@gotlinux.nl
#-----------------------------------

me=$$

export $(cat /proc/$(pgrep -u `whoami` ^gnome-shell$)/environ | grep -z DBUS_SESSION_BUS_ADDRESS)

BGDIR=/home/leon/images/hd_wallpapers/

if [ -z $1 ]; then
    NEWBG=$(ls $BGDIR | shuf -n1)
else
    NEWBG=$(ls $BGDIR | grep $1 | head -n1)
fi
#export DISPLAY=:0 
DISPLAY=:0 GSETTINGS_BACKEND=dconf /usr/bin/gsettings set org.gnome.desktop.background picture-uri file://///"$BGDIR$NEWBG"
echo "$BGDIR$NEWBG" > /home/leon/current-bg.txt

 

And to run it every X minutes, save it somewhere convenient, like in ~/rand-bg.sh and set a cronjob:

 

*/5 * * * * /home/leon/rand-bg.sh > /dev/null 2>&1


Share: