Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr2054 :: Blather Configuration Part 1: Desktop Management

Blather Configuration Part 1: Desktop Management

<< First, < Previous, , Latest >>

Thumbnail of Jon Kulp
Hosted by Jon Kulp on Thursday, 2016-06-16 is flagged as Clean and is released under a CC-BY-SA license.
Accessibility, speech recognition, linux, scripting. 2.
The show is available on the Internet Archive at: https://archive.org/details/hpr2054

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:24:56

Accessibility.

Shows about tearing down the barriers for our fellow hackers.

Blather Configuration Part 1: Desktop Management

In this episode I show how to start adding more commands, how to use the language updater script, and how to start doing some basic desktop navigation. I'll show you how to open and quit applications, and how to switch from one application to another using your voice.

For information about installing blather for the first time, as well as the startup script that I use, please refer to episode 0 of this series, which has examples and links for this stuff.

To start using the language updater script, you need to move it or copy it from the blather source code directory into your path (e.g. ~/bin/). To add new commands you will have to edit the main command configuration file:

~/.config/blather/commands.conf

Commands are configured in a "key: value" pair, where the key is what you wish to say, and the value is the command that will be executed when you say it. We will start out with some very basic ones, but these can be as elaborate as your imagination and scripting skills will allow. You can execute built-in system commands, or you can write your own scripts that will be executed upon the voice command.

Here's an example of a basic desktop application command set:

OPEN CHROMIUM: chromium &
GO TO CHROMIUM: wmctrl -a "google chrome"
QUIT CHROMIUM: wmctrl -c "google chrome"

The first command launches Chromium, the second one will switch focus to Chromium when you are currently in another program, and the third one closes Chromium. This makes use of the command line tool wmctrl, which is a very handy window management tool. The wmctrl -a command chooses which window to put focus on (or close) based on the window title, which in the commands above is given in quotation marks. There are many options to how wmctrl can find windows and take actions, but for now we will just use this basic option.

Once you have one command set of this kind working as you like, it's very easy to set up additional command sets for all of the desktop applications you use most often.

Some applications are more difficult to handle than others. For example media players typically change the window title based on which track is playing. This makes it impossible to use the static window title option above, so I resort to a bit of scripting to help it find the right window to put focus on or close:

OPEN clementine: clementine &
GO TO clementine: rid=$(pgrep clementine -u $(whoami) |head -n 1) && rwinname=$(wmctrl -lp |grep $rid |sed -e "s/.*$rid * //" | sed -e "s/$(hostname) //") && wmctrl -a "$rwinname"

Opening the music player is easy. Switching to it is something else. To make this work I first find the process ID of the Clementine music player, and then I use the wmctrl list command to list all of the windows that are open and I grep for the process ID that I found in the first part. Then I extract the window name from that command's output and use the result inside quotation marks in the very last command to change Focus to that window. Whew!

One last basic desktop navigation command for this episode. This is one that I use probably more than any other command. What it achieves is the alt + Tab Key stroke, which switches Focus to the previous window. Here's how I do it:

BACK FLIP: xdotool key alt+Tab

This makes use of the wonderful xdotool package to execute a virtual keystroke. Magic!

Links


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2016-06-17 13:12:06 by amunizp

Headless?

Would this work for headless computers. I mean opening and closing minetest server running on a single board computer.

Comment #2 posted on 2016-06-17 19:54:07 by Jon Kulp

Probably

Yes, I think so. I'm pretty sure that Jezra uses this on a headless computer in his house. You might go back and listen to my interview with Jezra from episode 1284 (https://hackerpublicradio.org/eps.php?id=1284) and see what he says about it.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
Who is the host of this show?
What does HPR mean to you?