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


Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

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

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 2 comments… read them 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…

2 Hutchy July 22, 2014 at 5:38 am

Another Way That I add wallpapers without having to install feh is to use the “fbsetbg” command like this example where I might select 2 or 3 favourite wallpapers I have in /usr/share/wallpapers or /backgrounds Folder & add to menu like this

[exec] (SetFluxBox-WallPaper1) {/usr/local/bin/fbsetbg /usr/share/wallpapers/YourWallPaper.jpg}
[exec] (SetFluxBox-WallPaper2) {/usr/local/bin/fbsetbg /usr/share/wallpapers/YourWallPaper.jpg}
[exec] (SetFluxBox-WallPaper3) {/usr/local/bin/fbsetbg /usr/share/wallpapers/YourWallPaper.jpg}

Very simple & you just click on the background you want,thanks for your examples too.

Leave a Comment

Previous post:

Next post: