Monday, September 22, 2014

random wallpaper script for nitrogen

Tested this in Openbox in Kubuntu 12.04. Create the following script, substituting your preferred directory path for [wallpapers-directory], save the file, and make the file executable:

#! /bin/bash
WALLPAPERS="[wallpapers-directory]"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[@]}
let "number = $RANDOM % $RANGE"
nitrogen --set-centered --save $WALLPAPERS/${ALIST[$number]}

I saved the file as /home/steve/wallpaper-script-nitrogen and added that command to ~/.config/openbox/autostart. I also added a “random wallpaper” entry in the Openbox menu (using the same command) so that I can switch to a random wallpaper on demand.


See man nitrogen and nitrogen --help for more info on options to use with the nitrogen command in the above script. This script should also work fine using feh instead of nitrogen. Thanks to "uname" for providing this in post #26, here in the CrunchBang forums.

No comments: