fedops blog

Privacy in Computing

Thu 05 May 2022

dmenu/rofi Scripts

Posted by fedops in Software   

Fans of tiling window managers generally do not have a full-featured desktop environment such as Gnome or KDE installed. One of the more obviously missing UI elements is the search bar for quick access to programs and to search for things.

dmenu is an extremely versatile utility that can best be described as the equivalent to the fuzzy finder fzf, just for graphical user interfaces. In general terms it presents the user with a list of choices that can be filtered and one of them can be selected.

The original use case was as an application launcher. A supporting script searches the user's $PATH for executable files and presents the results as a list on standard-input to dmenu. The user can then chose a program which will be started.

Similarly one might search for URLs in a bookmarks file or bitmap files in the ~/Pictures hierarchy, etc. The "magic" is in creative ways of producing input to dmenu.

Over the years lots of forks happened, and also other programs came along that included and expanded on dmenu's functionality. One of them is rofi which is the one I prefer to use - not least because, unlike dmenu, it supports Wayland.

I have come up with a couple of use cases which I've collected and adapted. The scripts can be obtained from my scripts repository.

dmenu_keys

A handy keybinding reference, specific to sway. It parses the sway config for bindsym keybindings and displays them. Selecting one of them will also execute the command.

This is useful for memorizing seldom-used keys in tiling window manager environments.

searching for dmenu keybindings

dmenu_calc

A minimal calculator inside a rofi menu. The result is displayed inside rofi and can also be copied to the clipboard.

result of 4*11 calculation

dmenu_emoji

An emoji picker. It reads the emoji file from ~/bin/emoji. It is extremely generic and can be used for anything else simply by providing a different file to read the entries from.

The selected emoji gets copied to the Wayland clipboard and can then be pasted into any program.

emoji picker in action

dmenu_sound

And lastly there is dmenu_sound. If you have multiple audio devices attached, such as a monitor with loudspeakers or a USB DAC, this script can be used to switch audio outputs on the fly. It will list the given audio sinks, indicating the currently active one, and upon user choice will switch to a different one and play a short jingle to indicate things are working.

sound sink picker in action

In this example it found and displays the built-in laptop audio, the 5 different HDMI sound inputs in my monitor, and an old Griffin iMic DAC/ADC on USB. After selecting an input, a notification pops up for a few seconds:

sound sink notification

It makes use of the Pulseaudio utilities, specifically pactl. I would have liked to use only native Pipewire utilities, but for reasons unknown there is no consistent way of listing the available sinks in a useable format. If you run Pipewire things should work as long as you also have a Pulseaudio server part (tested on Fedora 35).

The other thing that is extremely annoying about this constellation is that Pulseaudio and Pipewire do not agree on what the outputs are called and how they should be numbered. So for example 52 in Pulseaudio is 39 in Pipewire. As if Linux audio wasn't already confusing enough...

rofi configs

There are lots of different themes available for rofi on the Net. The configs subdirectory has the configuration files for the flat orange theme visible in the screenshots.

Hope these are useful. Feel free to adapt them to your use cases.