Skip to content

Instantly share code, notes, and snippets.

Created Feb 13, 2014
What would you like to do?
Background manager, setter, tiler, mirrorer, etc - using mostly feh and imagemagick
# Quite a bit of inspiration from
# I have a lot of backgrounds, and a laptop. I use xinarama, so my DISPLAY is always 0:0
# But I wanted to have one randomizer that used feh (2.9.3 is the version I have) but actually showed resolution-appropriate images.
# I also wanted to be able to select the color - "tiled", "orange", "blue", "black", "simple", "wide" (hooray for symlinks) at times.
# Uses xrandr to see if there is an HDMI monitor attached (which in my use cases always means I am rocking two monitors
#sets background
if [ "$1" == "tile" ]; then
#tiled, we don't care about splitting or how many monitors
file=`find -P "/path/to/my/backgrounds/tiled" -mount -maxdepth 8 -type f | sort --random-sort | head -1`
export DISPLAY=:0.0;feh --bg-tile "$file"
if [ "$1" == "" ]; then
file=`find -H /path/to/my/backgrounds -type f \( -name "*.jpg" -or -name "*.png" -or -name "*.jpeg" \) | grep -v "tiled" | sort --random-sort | head -1`
file=`ls -1 /path/to/my/backgrounds/$color/* | sort --random-sort | head -1`
#do we have more than one monitor?
hdmiconnected=`xrandr | grep "HDMI1 disconnected"`
hdmivalue="HDMI1 disconnected (normal left inverted right x axis y axis)"
# only one monitor
if [ "$hdmiconnected" = "$hdmivalue" ]; then
# we have one monitor
export DISPLAY=:0.0;feh --bg-fill --no-xinerama "$file"
#is the wallpaper wide enough to span both?
imgwidth=`identify -format "%w" "$file"`
if [ "$imgwidth" -lt "2000" ];then
#so we mirror it
cp "$file" /tmp/wallpaper-0.jpg
convert "$file" -flop /tmp/wallpaper-1.jpg
#we need to split wallpaper
nice -n 19 convert -crop 50%x100% +repage "$file" /tmp/wallpaper.jpg
DISPLAY=:0.0 feh --bg-scale /tmp/wallpaper-0.jpg /tmp/wallpaper-1.jpg &
#echo "$file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment