Follow up to xdotool doesn't work nicely

My previous post was that Windows “just works”, and Linux was “good luck with that”. Indeed, I had a deadline, and to get the job done, I used Windows and WinBatch, just got it done. On time. On a laptop. In my car. Yay.

But really, my nice setup is here at home, instead of on the laptop in my car. And my preferred setup is this OpenSuSE box here at home. So, now that the time pressure is lessened, I can spend a little more time, trying to figure it out. The secret is to not use the one-liner feature of xdotool. If you do the one-liner format of xdotool, it composes the command to throw at the window with “XSendEvent”

If you do multiple xdotool commands in order, it composes the commands to throw at the window with “XTEST”

More accurately, if the xdotool command has –window in the line, then XSendEvent is used. If xdotool command has only the “key” command in it, XTEST is used.

Apparently, most programs ignore window commands send with XSendEvent, so xdotool does it’s tool do to X, and the window ignores it.

Yay.

Here is one of the scripts that finally worked. Note I did have to add a time delay in, because otherwise the audio player window wasn’t ready in time for the following key stroke to be input.

!/bin/bash
 WIDLibre=$(/usr/bin/xdotool search --name "LibreOffice Writer")
 WIDAudio=$(/usr/bin/xdotool search --name "Insert Name Of Window of audio player here")
 /usr/bin/xdotool windowactivate $WIDAudio
 /usr/bin/sleep 0.5
 /usr/bin/xdotool key Control_L+comma
 /usr/bin/xdotool windowactivate $WIDLibre

This script sends a comma (with the Control key modifier) to the audio player. In WinBatch, this would be SendKey("^,")

Ctrl+, is the pause / unpause keystroke for the audio player. The other script, uses the left arrow key to rewind the audio. One script each is attached to a couple KDE shortcuts. Each of those keytroke combinations is programmed into a Kinesis Savant Elite2 foot pedal. So the left pedal backtracks the audio a few seconds, and the right pedal pauses / unpauses the audio. Window focus remains in LibreOffice.

To figure out what to use for “Insert Name Of Window of audio player here“, use the command wmctrl -l

One thing to note: the full name of the window (because of the audio player I used) had the length of the audio in it. That time had special characters in it (colons to separate minutes from seconds); so either I would have had to escape them out, or, I just put the first part of the window name in, up to the time / length.

The whole secret to the thing was that this did not work:

/usr/bin/xdotool --window $WIDAudio key Control_L+comma

and this did work:

/usr/bin/xdotool windowactivate $WIDAudio
/usr/bin/xdotool key Control_L+comma

Windows "just works" versus Linux "good luck with that"

I’m trying to do some audio transcription, so that I have text to go along with the audio. Transcription is still quite the labor intensive problem, even here a few months away from 2020. Sure, I can get Amazon to do a basic transcription for very little cost (pennies more than dollars); but, the transcription isn’t very good. Part of the problem is that one of the speakers has a thick Southern accent.

Fine, whatever – I’ll just fix it.

Years ago, I was a “programmer” for an NC Drill. “NC” is the acronym for Numerical Control. So this drill just put holes in circuit board material at numerical X Y coordinates. My job was to digitize the artwork (or at least, line up the crosshairs on digitizer with the pads on the artwork, and then tap a foot pedal. As I spun the dials, the X and Y positions would be counted, and when I hit the foot pedal, the current position was recorded. (Actually, it was punched onto a paper tape).

So I learned that foot pedals are a nice way of interfacing with the computer. Especially with your shoes off. 😉

For this transcription work, I need to be editing a document (with my hands), but I’d like to pause and rewind the audio with foot pedals. I bought a somewhat expensive foot pedal from a company in the Pacific Northwest (Made in USA). It works well.

But what to have it do?

At first, I programmed it to do direct keystrokes: Alt-Tab to switch to the last window, Space to pause, Alt-Tab to switch back.

But this has the drawback that the last two windows I’ve used must be the one’s I need, and it’s terribly inflexible. How about picking an un-used set of keys as shortcuts / hotkeys, and attaching scripts? This way, the script can pick the name of the window from the open list, and go right there no matter if it’s been pushed to the back by something else.

Windows, with WinBatch, it just works.

Linux, with xdotools is a nightmare. Someone said xvkbd is the right way to go, to get around the fact that xdotools doesn’t work. Tried the combo, and now one run of one of the scripts kills off the other script from being able to work. I’ve got both, because xdotools does know now to do a “WinActivate” (to use WinBatch terminology), and it doesn’t appear that xvkbd doesn’t do window management. And it wasn’t written for that, either. But xdotools doesn’t know how to send the Space character to the media player, so I’ve got to mash these two together.

The xdotools people say it’s not their fault; most applications block input. Although somehow the xvkbd people are managing it.

I’ve used xdotools at work, and it does great with mouse clicks; so there’s that. But VLC and other Linux media players (many based on VLC) refuse to use a mouse click as “pause” for the video (where YouTube and Facebook don’t have a chip on their shoulder, and just do what is natural for people).

Anyway, I had a deadline to meet, and Windows actually got the job done.