Zenity and Simple Front Ends

I mentioned in an earlier entry that I was using zenity to get a color name for the foreground (text) color in aterms. This means I can use one menu entry and select colors on the fly so I don’t have to mess about with adding new entries or opening new terminals from one if it clashes with a background or something, much less avoid re-editing .Xdefaults every time I want to change settings.

Zenity is a tool that allows a fast GUI to be built for a shell script. It also works great for menu entries. This is an example entry in my jwm menu for basically the same described above except it executes SSH to my account on another computer.

<Program label=”ssh – choose color”>ansColor=$(zenity –entry –title “ssh color” –text “what color terminal do you want?”);aterm +sb -tr -fg $ansColor -cr $ansColor -pr $ansColor -e ssh user.name@path.to.computer & exit</Program>

I could make that a script (preferable since hitting “cancel” will give me a default aterm executing ssh to that computer) and call the script instead from the menu or bind it to keystroke. Or include a choice for other computers where I have access — zenity has several ways to handle that including menu dialogs. I could also use other tools in zenity to select if I want scrollbar, transparency, etc., per instance of aterm, and whichever settings I want for ssh. Regardless of complexity desired, it’s very simple to create an interface with zenity like this or by just piping output. Such as this other entry to check my temperature:

<Program label=”temperature”>cat /proc/acpi/thermal_zone/THR2/temperature | zenity –text-info –title=cpu-temp –width 350</Program>

Drawbacks: zenity is GTK2 so it’s not exactly small or light on resources. But I don’t run lengthy processes in it (just long enough to get or input information — note the “& exit” in the aterm command above to terminate zenity) and its flexibility makes it acceptable for what I’m using since I have GTK2 on the system anyway.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: