blob: cd5ffe78784d3e3bb860942224ad3020555bdb5f (
plain)
1 #!/usr/bin/env bash
2 #
3 # Recursively searches the specified directory (the first script argument),
4 # randomly selects one image, and set that image as the wallpaper.
5 #
6 # Usage:
7 # random_wallpaper.sh /path/to/wallpapers
8 #
9 # Requirements:
10 # feh
11 #
12
13 # Check for feh
14 which feh 2>/dev/null 1>/dev/null
15 if [[ $? == 1 ]]; then
16 echo "Required program 'feh' not found. Please install and run again."
17 exit 1
18 fi
19
20 # Make sure a wallpaper path was specified
21 if [[ -z $1 ]]; then
22 echo "Please specify a wallpaper path."
23 exit 1
24 fi
25
26 # This needs to be set if scheduling in crontab since crontab don't have
27 # displays
28 # export DISPLAY=:0
29
30 search_path=$1
31
32 # Randomly select a wallpaper to set
33 picture=$(find ${search_path} -type f \
34 -name '*.jpg' \
35 -o -name '*.JPG' \
36 -o -name '*.png' \
37 -o -name '*.PNG' \
38 | sort -R | head -n 1)
39
40 # Set the wallpaper
41 feh --bg-fill "${picture}"
|