Skip to content

Instantly share code, notes, and snippets.

@cfstras
Last active October 3, 2015 01:08
Show Gist options
  • Save cfstras/2360075 to your computer and use it in GitHub Desktop.
Save cfstras/2360075 to your computer and use it in GitHub Desktop.
Background-changer script for GNOME 3
#!/bin/bash
# background-changer
# 2012-04-06
# use to switch gnome background to a random one
# uses every file in bg_path and follows the first symlinks in that directory
# outputs the selected file
# author: cfstras <c@cfs.im>
# license: beerware
#
# use for example in a crontab:
# 0,15,30,45 * * * * background >>/tmp/background.log 2>&1
#
bg_path="/wallpapers"
exts=".jpg
.png
.PNG
.JPG
.JPEG
.bmp
.BMP
.gif
.GIF
.JPEG
.jpeg
.tiff"
#set Display
DISP="$(cat /proc/$(pgrep -u `whoami` gnome-session)/environ | tr "\0" "\n" | grep DISPLAY)"
[ "$DISP" ] || die "background: Unable to get DISPLAY variable from environment"
eval export "$DISP"
selected_bg=`find -H $bg_path/* -type f | grep -F "$exts" | sort -R | tail -n1`
gsettings set org.gnome.desktop.background picture-uri "file://$selected_bg"
echo "`date "+%y-%m-%d %T"` new background: "$selected_bg
notify-send --hint=int:transient:1 "new background: "$selected_bg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment