Using dmenu in Pekwm and Openbox

February 7, 2008

During my recent stint with Firebox, and before that while I was trying out wmii, I’ve grown very quickly accustomed to dmenu. After only using it for a few hours, I fell in love with it: it is so convenient to launch an application when you don’t have your hands on the mouse; launch dmenu, just type a few letters from the application name, make sure you have the right app selected, press enter and your app shows up.

Unfortunately, Firebox is still too unstable to use as a primary window manager, and I haven’t grown accustomed to tiling window managers (yet?). So I began to wonder whether it is possible to run dmenu or something similar in Openbox and Pekwm, and – guess what? – it is very easy! (Why did I ever think otherwise?)

First, you’ll need to install dmenu. You can download the source code from the dwm/wmii website and install that (‘sudo make clean install’ in Ubuntu). To launch dmenu in Openbox and Pekwm, I use the following command:

$(dmenu_path | dmenu -b -nb '#E0E9D0' -sb '#a6b38d' -sf '#070806')

This launches dmenu at the bottom of the screen (-b), with a colour scheme to match the Aeterna Openbox and Gtk theme. You can change the settings (everything that comes after ‘dmenu’ in the above command) to suit your preferences; read the man pages (‘man dmenu’) to see what options you have.

I have this bound to Alt+F3 in both Pekwm and Openbox (Alt+F1 launches the root menu and Alt+F2 launches gmrun). In Pekwm, I added the following to keys file:

KeyPress = "Mod1 F3" { Actions = "Exec $(dmenu_path | dmenu -b -nb '#E0E9D0' -sb '#a6b38d' -sf '#070806') &" }

To get dmenu to work in Openbox was a little more complex. If I added the above command to the rc.xml file dmenu wouldn’t launch (Openbox-Message: Failed to execute ‘$(dmenu_path | dmenu’)’: Failed to execute child process “$(dmenu_path” (No such file or directory) say the xsessions-errors.). I’ve tried adjusting the command in several ways, but couldn’t find one that did work, so I ended up creating a script to launch dmenu in Openbox. It is very straightforward:

#!/bin/sh
exec $(dmenu_path | dmenu -b -nb '#E0E9D0' -sb '#a6b38d' -sf '#070806')

I saved the file as OBdmenu in ~/.scripts, where I keep all my scripts, made it executable (chmod +x ~/.scripts/OBdmenu), and added the following to the rc.xml file

For Openbox, this is what I added in the <keyboard> section of the rc.xml file:

<keybind key="A-F3">
<action name="Execute">
<execute>/home/urukrama/.scripts/OBdmenu</execute>
</action>
</keybind>

Here is a screenshot of dmenu running at the bottom of the screen in Openbox:

OBdmenu

The only downside to using dmenu in this way is that the applications launched by it don’t show up with their application name in your favourite system monitor, but as the command you used to launch dmenu (OBdmenu in my Openbox session, $(dmenu_path etc. in my Pekwm session). I have no idea how to get around this, but it is only a detail. Otherwise, dmenu is fantastic. It won’t replace my right-click root menu, but it is a great addition to any window manager.

Update: As Tami points out in a comment below, you can get around this problem if you use the following command to launch dmenu:

`dmenu_path | dmenu -b -nb '#E0E9D0' -sb '#a6b38d' -sf '#070806'` && eval “exec $exe”

In Pekwm, you can use this command in the Keys file, but in Openbox you’ll still have to use a script to launch dmenu (as explained above).

This should also work in other window managers, such as Fluxbox, or desktop environments like Xfce, though I haven’t tried it.

11 Responses to “Using dmenu in Pekwm and Openbox”

  1. tamihania said

    Hi! And first of all – thank you for your fantastic tutorials – great job! You introduced me to PekWM – and I’m very glad for it.
    As to the problem with the path of applications launched by dmenu – I have a slightly different approach – so, maybe this will be of a help:
    I made an entry in PekWM’s menu:

    Entry = “dmenu” { Actions = “Exec ~/bin/dmenu_bind.sh &” }

    which leads to a veryy simple bash script:

    #!/bin/bash
    exe=`dmenu_path | dmenu` && eval “exec $exe”

    (called “dmenu_bind.sh”, of course)

    The applications launched by dmenu this way appeared correctly in top and htop.

    I think you can easily use the script to bind it with the keys.

    Wishing you nice day – and thank you once again,

    tami 🙂

  2. urukrama said

    Thanks, tami. That does indeed solve the problem. 🙂

  3. Mikachu said

    Openbox doesn’t run commands through /bin/sh, so if you want to use shell code, you have to say you want to use a shell, for example by writing
    sh -c ‘lala && dmenu -foo $(blabla)’

  4. Mikachu said

    damn, i even wrote &amp;&amp; in the comment box, trying double quoting it now 🙂

  5. HT said

    Thx for the tips, I use wmii alot and dig the dmenu but have now found a clone of dwm you should check out called : awesome !! and that is what it is check there web site :
    http://awesome.naquadah.org/
    and it is pretty easy to and dmenu as a menu bar.
    just edit the ~/.awesomerc file , ex. attach it to a key stroke :
    key
    {
    modkey = {“Mod4”}
    key = “x”
    command = “spawn”
    arg = “exec $(dmenu_path | dmenu -b -nb ‘#000000’ -nf ‘#FFFFFF’ -sb ‘#a6b38d’ -sf ‘#070806’)”
    }

    in the keys{…}

    keep it nice

    peace
    HT

  6. Cody said

    Do you remember the wallpaper you were using in that screenshot?

  7. urukrama said

    It is a modification of “Sparkling green” created by *tumb.

  8. […] I wanted something a little more shortcut friendly, and something that would show up in dmenu, so I created a link to it […]

  9. dwindle said

    Hello, urukrama. =D I’ve been trying to use dmenu in xfce for a while but I can’t get it to execute commands. It only seems to “type” the command but not execute (when I run it from a terminal the program I selected is typed on a newline in the terminal but isn’t executed). Would you know why?

  10. JD said

    Very nice blog; interesting read.

    Thank you, keep up the great work.
    JD

Leave a comment