I am using Ubuntu 20.04 and its default desktop and I can't manage to trigger a cnee macro using a keyboard shortcut.
I have recorded a simple macro with cnee and saved it in the file /tmp/recorded_macro.xnl
. If I use the following linux command in a terminal, the macro is played correctly (my macro simply types "test" in the terminal):
cnee --replay -sp 0 -f /tmp/recorded_macro.xnl
Now I would like to use a keyboard shortcut to start this same macro when the focused window is a text editor (e.g., emacs, visual studio, gnome-terminal, ...). The aim is to write "test" in the focused window. To that end, I created a keyboard shortcut which triggers the exact same cnee
command and tried it when the focus is on several text editors. Unfortunately, nothing is written in the editor when I use the shortcut.
To check that the shortcut is correctly triggered, I created the following script and associated it with another keyboard shortcut:
#!/bin/bash
cnee --replay -sp 0 -f /tmp/recorded_macro.xnl
touch /home/user/test
If I execute the script in a terminal, it works ("test" is written in the terminal and the file /home/user/test
is created).
However, when I use the shortcut when the focus is in a text editor, the file "test" is created (so the script is executed) but no text is written in the text editor.
Do you know why and how I could fix this?
To trigger the cnee command, I was using the shortcut:
Ctrl+Shift+H
.Since I was using the replay speed
-sp 0
, the keys 't', 'e', 's' and 't' were "pressed" instantly.It was so fast that the keys
Ctrl
andShift
of the shortcut were still pressed. Consequently, the editor instead of writting "test" was interpretingCtrl+Shift+t
,Ctrl+Shift+e
,Ctrl+Shift+s
andCtrl+Shift+t
.A solution is to add a small delay before executing the cnee replay by adding
-t 1
. It is not totally satisfying for me, since executing the macro several times in a row will make me wait a little each time but it works.Thanks to @WU-TANG for the help.
EDIT: One workaround would be that the shortcut triggers a bash script which waits until
Ctrl
andShift
are not pressed anymore to execute the cnee command. I don't yet know how to do that in bash however.