Skip to content

Instantly share code, notes, and snippets.

@tohn
Last active June 15, 2016 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tohn/bdacae965b1f3b4a48a5 to your computer and use it in GitHub Desktop.
Save tohn/bdacae965b1f3b4a48a5 to your computer and use it in GitHub Desktop.
Change wallpaper
#!/bin/bash
# change me
root="$HOME/pics/wallpaper"
# dependency
command -v feh >/dev/null 2>&1 || { echo >&2 "$0 error: missing dependency (\"feh\")"; exit 1; }
# reason for this here: http://yhaupenthal.org/1265597121.htm
export DISPLAY=:0.0
# get the resolution of all monitors together
res=$(xrandr | head -1 | tr -d ' ' | cut -d\, -f 2 | sed 's/current//')
src="$root/$res"
if [[ ! -d "$src" ]] ; then
echo >&2 "$0 error: no such folder (\"$src\")"
exit 1
else
# how many files in $src
lines=$(ls "$src" | wc -l)
# get a random number
rand=$(shuf -i 1-"$lines" -n 1)
# get the pic belonging to the number
pic=$(ls "$src" | sed -n "${rand}p")
# show it with feh
feh --bg-tile "$src/$pic"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment