hpr2054 :: Blather Configuration Part 1: Desktop Management
Blather Configuration Part 1: Desktop Management
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
- Blather setup (first episode in the series)
- CLI tools: xdotool, wmctrl
- snapshot of my blather commands file