I was looking into getting a little more random for my wallpaper and decided to write a quickie little commandline to get a couple new random pictures from my wallpaper directory. Looking at how the conkyPhotoRandom script from conky-colors does it, I came up with:
The cool part of this is the shuf command, which I didn't know about (or, just as likely, knew but forgot about). So this feeds a list of files from my wallpaper folder and randomly chooses two of them. I use 2 because I have 2 monitors, each displaying 1920x1080 and the 'feh' command takes two files and scales them for my background. Maybe I'll just set this as an alias and do it whenever I think of it.
Edited: Of course, you have to take into account spaces in the filenames. So I had to add the various options that use \0 as a line delimiter, rather than \n. In this case, -print0 tells find to end each line with a \0, -z tells shuf the lines end in \0, as does the -0 option for xargs.
shuf(1): make random permutations - Linux man page
$ find /home/jdarnold/data/wallpapers -type f \( -name "*.jpg" -or -name "*.png" -or -name "*.JPG" \) -print0 | shuf -z -n2 |xargs -0 feh --bg-scale
The cool part of this is the shuf command, which I didn't know about (or, just as likely, knew but forgot about). So this feeds a list of files from my wallpaper folder and randomly chooses two of them. I use 2 because I have 2 monitors, each displaying 1920x1080 and the 'feh' command takes two files and scales them for my background. Maybe I'll just set this as an alias and do it whenever I think of it.
Edited: Of course, you have to take into account spaces in the filenames. So I had to add the various options that use \0 as a line delimiter, rather than \n. In this case, -print0 tells find to end each line with a \0, -z tells shuf the lines end in \0, as does the -0 option for xargs.
shuf(1): make random permutations - Linux man page


