Getting nitrogen to sort the image listing alphabetically

18Feb12

CrunchBang Linux (with the Openbox window manager) comes with a wallpaper browser and setter called nitrogen. I won’t go into any detail of how to use nitrogen, because I feel its menu is straightforward enough for even a beginner to use without any difficulty. Instead, what I want to talk about is how to use alphabetic sorting with nitrogen.

This is something that bugged me right away about nitrogen, by default when you launch it, the images are not sorted in any way useful to me. According to the nitrogen man pages:

By default, items are sorted as they are found on the filesystem, giving a quasi-newest first sorting order.

I always use one of two types of sorting when browsing files: modification time or alphabetic. In the case of wallpapers, I prefer to have nitrogen sort these alphabetically. And if you’re into that type of stuff too, here is how it’s done.

First, let’s see what nitrogen looks like without sorting. To do this, you need to launch nitrogen. In Openbox, simply right-click on the desktop and go to Settings and then click on Choose Wallpaper.

As you can see by the file names, the images listed by nitrogen are in no particular order, which can make it difficult for me to find wallpapers. And I usually end up scrolling up and down, looking for that right one….. I know it’s here somewhere…

Going back to the man pages, let’s see what it says about sorting:

$ man nitrogen

–sort=[option]
Sorts  the  background list by the given option.  By default, items are sorted as they are found on the filesystem, giving a quasi-newest first sorting order.  Valid options are:

              alpha  Alphabetical order.

ralpha Reverse alphabetical order.

time   Modified time, ascending.

rtime  Modified time, descending.

–sort=alpha /path/to/folder/containing wallpapers. Wonderful. Just what I was looking for. 🙂

Now that we know how to get nitrogen to alphabetically sort our wallpapers, we could open up a terminal and type (in my case):

$ nitrogen –sort=alpha ~/images/wallpapers

Please note those are two ‘-‘. Not one. WordPress is making it look like it’s just one minus, and I don’t know how to change that.

Everytime we need to use nitrogen. Or to make things easier we could just put this in ~/.config/openbox/menu.xml so that everytime we launch nitrogen through the Openbox menu, the images are already alphabetically sorted.

Open menu.xml with your favourite text editor. Mine happens to be vim, but you could also use Geany, which also comes default with CrunchBang Linux since Statler R20111125.

$ vim ~/.config/openbox/menu.xml

menu.xml is the configuration while for the Openbox menu. You can find all the right-click menu entries in there and easily tweak them to your needs. Make sure you backup the file before every edit. That way, if you muck something up, you could always go back to a last known good config.

Find the line where the nitrogen menu entry is. At the time of writing this blog post it should look like this, by default. Look at the line where my cursor is:

Default menu.xml
And so we make the necessary changes to get nitrogen to always launch with alphabetic sorting. This means we add the –sort alpha option. Note that the path ~/images/wallpapers/ is the path to the folder where I save all my wallpapers. Make sure you have that set to the path where you save your wallpapers.

nitrogen --sort=alpha ~/images/wallpapers

Save the menu.xml file and close it. In order for these menu changes to take effect, you will need to reconfigure Openbox. Right-click on the desktop and go to Settings, then to Openbox and click on Reconfigure.

Openbox Reconfigure

So, if you launch nitrogen again, you will see that the images are now listed alphabetically, which I think is a much more usable approach. Now, if I could only get round to giving all my wallpapers descriptive file names, then this would be even more usable. 😉

nitrogen sorted

Note: On my netbook (Intel(R) Atom(TM) CPU N450   @ 1.66GHz) launching nitrogen on a folder with lots of hi-resolution wallpapers tends to max out my CPU. The 50%-65% CPU usage by nitrogen tends to push the CPU all the way up to 100%. So, I try to be quick about it, in and out. Use at your own risk.

EDIT: As pointed out by Kris in the comments (3):

**IMPORTANT** -if you have nitrogen hotkeyed (i have mine set to W+n) you also need to add the “–sort=alpha [path]” line to the execute command in your rc.xml file as well as the menu.xml



6 Responses to “Getting nitrogen to sort the image listing alphabetically”

  1. 1 Kris

    Thank you! That has been bothering me for a while. You are a savior to those of us too lazy to do the legwork ourselves.

  2. 2 istok

    first of all, excellent tip, very helpful.
    second,
    “a quasi-newest first sorting order…”
    that is one dopey default 🙂

    thanks again.

  3. 3 Kris

    **IMPORTANT** -if you have nitrogen hotkeyed (i have mine set to W+n) you also need to add the “–sort=alpha [path]” line to the execute command in your rc.xml file as well as the menu.xml

  4. where can one get dat wallpapaer?!?! 😀
    kudos


Leave a comment