How To Change Wallpaper in Fluxbox Window Manager

by Leonardo Sanchez on February 5, 2010

Question: How do I change the desktop background wallpaper in fluxbox window manager?

Answer: We discussed fluxbox earlier in an introduction to the fluxbox window manager and how to shutdown the system from fluxbox window manager.

In this article we’ll see how to change the wallpaper in fluxbox by using a bash script or by editing the menu file.

We use a BASH script to aid us and it will be stored in ~/bin so it is readily accessible. Make sure that your $PATH is set correctly. Do this by adding the following line to your ~/.bashrc.

PATH=$PATH:~/bin

Install feh for fluxbox wallpaper

First step is to install feh. In Ubuntu and Debian you use the following:

sudo apt-get install feh

Whereas on FreeBSD you use the following:

sudo pkg_add -r feh

Write a bash script to set the fluxbox wallpaper

The next step is to write a script which I’ve already taken the liberty of writing.

#!/usr/bin/env bash
BG_TILE="--bg-tile"
BG_CEN="--bg-center"
BG_SCA="--bg-scale"
USAGE="Setting background:\n-t tiled\n-c center\n-s scaled\nsecond arg should be a pic"
#
if [ "$1" = "-t" ]
   then feh $BG_TILE $2 

elif [ "$1" = "-c" ]
   then feh $BG_CEN $2 

elif [ "$1" = "-s" ]
   then feh $BG_SCA $2 

else
   echo -e $USAGE
fi 

if [ ! -e "$2" ]       # Check if file exists.
   then
      echo "Are you sure you typed the filename correctly?"
fi

What this script does is execute certain commands based on certain conditions. The first part says if $1 (the first argument) is equal to “-t” then execute feh $BG_TILE $2, where $2 is the second argument, i.e. the path of the fluxbox wallpaper.

Set wallpaper by editing fluxbox menu

Another and even simpler way to set the fluxbox wallpaper is by editing the menu file. You can add something like the following somewhere in your menu file and you’ll get a list of all your fluxbox wallpapers (bear in mind that it won’t read subdirectories).

[wallpapers] (/path/to/wallpapers/) {command}

The “{command}” will be executed upon clicking. By default it uses fbsetbg which is simply a wrapper. It will in turn use feh to set the background.

In closing, Fluxbox is an excellent window manager who’s functionality can be extended given some creative scripting, time, and patience. In addition, it being lightweight makes it ideal for low resource systems.

Fig: Fluxbox Change Wallpaper

Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

If you enjoyed this article, you might also like..

  1. How To Add Shutdown / Reboot Functionality to Fluxbox Window Manager for X
  2. Flexible for a Fluxbox? – Lightweight X Window Manager for UNIX / Linux
  3. Unix Shell Tips: Change Login Shell From Bash to Others
  4. Shell Script Execution Guidelines for Newbies
  5. How To Change Password On Ubuntu
  

Vim 101 Hacks Book

{ 1 comment… read it below or add one }

1 Vincent February 5, 2010 at 1:58 am

What benefit does the script give you. It does thing feh does by itself…

Leave a Comment

Previous post:

Next post: