What is termux-dialog and how I use it

Aug 06, 2021

I have been using Termux for several years, since I came back from iOS to Android. However, only recently I have explored termux-dialog, and this can be really be a game changer.

What is termux-dialog and why it matters

Needless to say, with Termux on your phone you can run (almost) the same scripts from your Linux box, or write new scripts specifically for your mobile device. Termux allows you to interact with your phone in several ways, such as accessing the file system, opening files and URLs in other applications, etc. It’s a very powerful application if you know what you are doing.

The termux-dialog command makes it even better by providing an easy way to grab user input, with a mobile UI. Run it and, as the name implies, a dialog will pop-up. There are several type of dialogs: text input, lists, time, date, etc.

I see it as a sort of dmenu for phones (or zenity, kdialog if you prefer floating WMs). It’s a graphical interface for user input. You first provide some options or ask a question, and with the user’s answer you determine what to do next.

The alternative to termux-dialog is to grab the input inside the Termux terminal. In this case, you could ease the typing by showing some kind of text or ncurses menu such as select in your Bash script. I used it in some occasions, and I’ll continue to in those situations when it makes sense to be in the terminal.

However, if the script doesn’t have any good reason to spawn a terminal on my phone screen, termux-dialog is the way. I couple it with termux-toast or termux-notification to give output to the user, and termux-widget for having a way of running it without the terminal. This results in a great mobile-like experience. Depending on your goals, you saved yourself from writing an APK or webpage from scratch.

How I use it: productivity system

I use some scripts for productivity and note-taking that I wrote tailored for my needs. With Termux, I can run them on my phone and still have a nice experience.

Using termux-widget, I have a list of actions ready to go. Tapping on it, termux-dialog will prompt me with whatever information it needs. For example, which command I want to execute, or what text I want to enter. Also, if a markdown file is opened next, I run VIM on my desktop, but on the phone I can run a markdown application, with the aid of termux-open.

A concrete example of this is my task logging. On my desktop I run tl Watered the plants. and this is added to my list of done tasks for the day. On my phone, I tap “task” on the widget. A popup asks me if I want to add or log a task. I tap log. A text input - with auto-correction - lets me write “Watered the plants.” Done.

How I use it: wake up time

Another way I use it is to track my wake up time, which I do daily for more than a year.

I used to keep this data on a spreadsheet, and then generate charts and calculate a couple of statistics. The data was entered mostly from my phone (as I did it just after waking up), and I have done so in three different ways:

My favourite approach was the second and it worked well. However, it still required to open the Google Sheets app, which is too much interface for so little I wanted to do. Yes, I had a shortcut for this specific workbook on my home, but the problem remains.

These days, following a bunch of changes on my productivity system, I decided to use Termux for logging this data. After putting together a Bash script, it works as the following:

What about the statistics? Well, this is as easy as importing the tsv file into my spreadsheet.

And this is a much better, non-intrusive experience.

Conclusion

I hope you can build some of your ideas using Termux, termux-dialog and its other tools, and unleash the power of your phone.


Have comments? E-mail me.

← All posts