07 June 2009


Nitrogen is a friendly tool you can use to set your screen's background image (i.e., wallpaper). To select a new background image, launch nitrogen from the command line, passing it the directory in which you store your background images:

nitrogen /path/to/background/images

This brings up a GUI from which you can select, stretch, etc. your desired image.

You can restore the most recently set background image with the command:

nitrogen --restore

If you place this command in your session startup scripts, every time you login to your session nitrogen will restore your background image.

The only problem with nitrogen is that its image browser expects to be told the directory to search for images. In other words, it does not have a built-in directory browser. To that end, I wrote the following little script to wraps nitrogen inside a directory selection GUI. Enjoy.
#! /bin/bash

# Mithat Konar 2009-06-07
# Wraps nitrogen inside a directory selection GUI.
# Requires: nitrogen, zenity

ui_browseTitle="Select a directory (Cancel to quit)"


while [ "$theDirectory" != "" ]; do
theDirectory=$(zenity --file-selection --title "$ui_browseTitle"  --directory --filename="${theDirectory}/");

if [ "$theDirectory" != "" ]; then
nitrogen --no-recurse "$theDirectory"


Anonymous said...

that is a very useful script!
how may i go about installing(?) it so whenever i start nitrogen, that dialog pops up?

thank you for your help

Mithat said...


I don't know of a way to initiate this script whenever you start nitrogen. However, you can place a copy of this script into '/usr/local/bin/nitrowrap' (no extension) and then use the command 'nitrowrap' from the command line (or add it to a menu) to start the script.

patriot said...

Alternatively, make sure your script is executable by running this from a terminal:

chmod a+x /path/to/script

Then, add this line to your ~/.bashrc

alias nitrogen='/path/to/script'

Now, whenever you type 'nitrogen' from within a bash terminal, your nitrogen wrapper will execute.

Mithat said...

Thanks for the tip. Do you know if the alias will affect other scripts? In other words, if in a bash terminal, I execute a script that itself calls nitrogen, will the aliased 'nitrogen' be invoked or the '/usr/bin/nitrogen'?

Anonymous said...

you can name an alias for this in ~/.bash_aliases and type in, say, nitrogenn or nitro or something similar. i find it more useful than linking to a script, as it's usable from openbox menus, ubu menus, terminal emulators, etc.