Last active
November 18, 2016 04:00
-
-
Save mathyourlife/40eae538d2897c0da5f88a5a86992dc5 to your computer and use it in GitHub Desktop.
script to dump in a user's crontab to rotate the background image based off a random image in the ~/Pictures/ directory
This file contains 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
#!/bin/bash | |
CACHE_FILE=~/tmp/pic-list | |
PID=$(pgrep xfce4-session) | |
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-) | |
USE_CACHE=false | |
if [ -e $CACHE_FILE ]; then | |
if [ $(date -r $CACHE_FILE +%Y/%m/%d) == $(date +%Y/%m/%d) ]; then | |
USE_CACHE=true | |
fi | |
fi | |
if [ "$USE_CACHE" = false ]; then | |
find ~/Pictures/ -name '*' -exec file {} \; | grep -o -P '^.+: \w+ image' > $CACHE_FILE | |
fi | |
# < instead of cat for @tom :) | |
IMAGE=$(shuf < $CACHE_FILE | cut -d ':' -f 1 | head -n 1) | |
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/workspace0/last-image --set $IMAGE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment