Sl-Alex home lab

Replacement of xdotool: xmacro

Views: 2160Comments: 0
Notes

Translation: RU

For those who don't know: xdotool - it's a small console program, which can emulate keyboard and mouse input. I used it together with irexec and lirc to control my computer. xdotool I used only to control sound volume by emulating multimedia keystrokes. Unfortunately, I found an unpleasant bug. Starting from some unknown version (I don't know the exact number, because I notice this behavior much later) xdotool refused to work correctly with non-english keyboard layouts. Moreover, after I switched to Debian, it started to hang for second before execute command.

I did not have time to deeply investigate this problem, but accidentally I found a great alternative. Its name is xmacro.

As for me - xmacro does the same things as xdotool, but it does not depend on keyboard layout and does not hang. Together with xmacro you will find xmacrorec2, which can be used to record keystrokes to file. xmacrorec2 is very simple to use:

xmacrorec2 log.txt

It will ask you to press a key, which later will be used to stop recording, and then it will start to record your keystrokes.

After recording keystrokes you can read log.txt and execute it with xmacro:

cat log.txt | xmacroplay  ":0.0"

If your sequence is not too long, you can write it in one-line command, like this:

echo "KeyStrPress XF86AudioRaiseVolume KeyStrRelease XF86AudioRaiseVolume" | xmacroplay ":0.0"

The same line I wrote in my ~/.lircrc config file, and I hope this short note will help somebody to solve similar problem.