Hosted by Jon Kulp on 2016-06-16 is flagged as Clean and is released under a CC-BY-SA license.
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.
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.
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.
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!
This makes use of the wonderful xdotool package to execute a virtual keystroke. Magic!
Would this work for headless computers. I mean opening and closing minetest server running on a single board computer.
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 (http://hackerpublicradio.org/eps.php?id=1284) and see what he says about it.