🍵️

2023-01-03

Program Picker With Zenity

Zenity is a small utility program for building simple graphical widgets and menus. I've never had use for it before, but a few days ago I ran into a situation that it just so happened to be perfect for.

I have a program of which I currently have several different versions compiled. Stable, release candidate, latest, etc. Since I start pretty much everything through gmrun (look that up: it's the best part of searching in the Gnome 3 menu, but without the bloat of Gnome 3) I didn't want to have to remember which versions I currently have. Wouldn't it just be better to run a command and pick from the currently available builds?

Enter zenity. This is a small script that for example purposes will be called /usr/bin/exampleprog


#!/bin/bash

cd /home/bjorn/exampleprog-builds

VERSION=$(zenity --list --title "" --text "Choose version" --column Version --hide-header *)

if [[ -n $VERSION ]]; then
        cd "$VERSION"
        ./start
fi

That zenity command is genuinely beautiful. Here's what the arguments mean:

This will produce a small window with a list that has a vertical scrollbar if needed. One entry in the list can be chosen, and there is a Cancel and an OK button.

If the user picks an element from the list and clicks OK that element will be returned from zenity. This is why I assign the output from zenity to the VERSION environment variable. If that output is a non-zero string we can use it, otherwise we just terminate gracefully.

-- CC0 Björn Wärmedal