From abc336dea1187f9d115a062d389c7c5ec730c144 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 20 May 2022 23:48:21 -0700 Subject: Initial commit --- pick-random-wallpaper | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 pick-random-wallpaper diff --git a/pick-random-wallpaper b/pick-random-wallpaper new file mode 100755 index 0000000..7a2b28c --- /dev/null +++ b/pick-random-wallpaper @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +function hc () { herbstclient "$@"; } + +function random-wallpaper() { + local rootinfo=$(xwininfo -root) + local width=$(echo $rootinfo | grep 'Width:' | sed 's/.*Width: \([[:digit:]]\+\).*/\1/') + local height=$(echo $rootinfo | grep 'Height:' | sed 's/.*Height: \([[:digit:]]\+\).*/\1/') + + find ~/pictures/wallpaper -type f \ + \( -wholename "*/${width}x${height}/*" -o -wholename '*/patterns/*' \) \ + -not -name '*.org' \ + | shuf -n 1 +} + +wallpaper=$(random-wallpaper) + +if ! hc attr my_wallpaper >/dev/null 2>&1 +then hc new_attr string my_wallpaper +fi + +feh --bg-tile "$wallpaper" && hc set_attr my_wallpaper "$wallpaper" -- cgit v1.2.3-54-g00ecf