Skip to content

Instantly share code, notes, and snippets.

@OrangeCrush
Last active June 2, 2016 04:42
Show Gist options
  • Save OrangeCrush/55f0c2099a3ec956871c to your computer and use it in GitHub Desktop.
Save OrangeCrush/55f0c2099a3ec956871c to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Randomly change wallpaper.
#
# Pass the directory to serve files from as the first arg
#
PICDIR=$1
[[ -d $PICDIR ]] || exit 1
#
# Allow the script to be run from cron
#
D_PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$D_PID/environ|cut -d= -f2-)
NUMPICS=$(find $PICDIR -type f | wc -l)
VAL=$((RANDOM % ($NUMPICS) + 1))
PICFILE=$(find $PICDIR -type f | sed -n ${VAL}p)
gsettings set org.gnome.desktop.background picture-uri file://$PICFILE
echo "[$(date)] Changed wallpaper to $PICFILE using file $PICFILE generated from random no $VAL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment