Saturday, February 12, 2011

Openbox random desktop wallpaper script

There are a lot of ways to change the desktop background of Openbox, but for this tutorial we are going to focus our thoughts on feh.

To set the background in Openbox, simply open a terminal and type the following command:

# feh --bg-scale /path/to/file.jpg

If you want to only use a single wallpaper for your desktop, the put this line in your autostart file:

# nano -w ~/.config/openbox/
# feh --bg-scale /path/to/file.jpg &

Remember the & at the end, very important!

Random wallpaper script
Let's take this one step further and take a look at a script that will randomly change the desktop wallpaper each time we log into Openbox.

Here is the script first:

ALIST=( `ls -w1 /path/to/folder/containing/wallpapers` )
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last

feh --bg-scale $WALLPAPERS/${ALIST[$number]}

Name it something easy and save it, on my PC all my scripts (conky, wallpaper, etc.) is saved in the same folder (~/.scripts). Let's name it

Make it executable:

# chmod +x .scripts/

Test the script by running it from a terminal:

# cd .scripts
# ./

If all went well you should see the desktop background changing. On my machine the script complained about a file (.last) not being present in the wallpaper directory, so just create that file:

# cd /path/to/wallpaper/folder
# nano .last
ctrl+o to save the file
ctrl+x to exit

No need to write anything in it, just create it.
If everything is working as expected, simply add the script to your autostart file:

# nano -w .config/openbox/ 

~/.scripts/ &

If you have problems with the script not being found, use the full path to the file:

/home/user/.scripts/ &

Log out and log back in, you should see a new wallpaper now!

Other alternatives
There are some scripts out there that allows you to change the desktop wallpaper with a menu click inside the Openbox right-click menu, if you want to try them out you can have a look here.

No comments: