Is there a script or program to record keys to an xdotool input file?

988 views
Skip to first unread message

Bob C

unread,
Mar 22, 2018, 7:58:02 PM3/22/18
to xdotool-users
I use a terminal based editor Tilde that doesn't have keyboard macros built in.  Its a great editor, but missing keyboard macros.

I want to turn on a record function and go to the editor, and perform a series of keystrokes, and then tell it to stop recording, and save it to a file, and maybe edit the file.

Then I want to be able to use xdotool to playback that recording to perform that same sequence of keystrokes on another document.

I can see that xdotool has the ability to input the file, but is there a good way to create the input file other than typing it in by hand separately?  It would be much better if it could watch and record while I do it?

I tried xmacro to record and it locks up the machine to the point of where it locks x-windows, and forced me to reboot.  Autokey is possible, but eats up 36 mb of memory.  I'm hoping there is a way to do it somehow by finding a program that can record an input file to feed xdotool.

Any ideas?

Anthony Thyssen

unread,
Mar 23, 2018, 12:04:29 AM3/23/18
to bcur...@yahoo.com, xdotool-users
While you could record things like mouse movements and key presses etc.  (XMacro you mention for example) I have found general recording and playback of X window events to be an impractical macro technique.

First windows positions may not be where they were when you recorded,  Then the window contents may not be what the macro expects.  Even if it clicks and types correctly, the response may not be what it expects, or worse still it is correct but comes back slower or faster than the macro expects.

Macros are basically deaf, dumb, and blind.  It is the same problem as robotics.  They work, but ONLY if every little detail is exactly as it is expected.  Things are never so simple.

As such Event Macros are generally not a good idea, unless you specifically program the macro to do a task.   That is not to say such 'taylored' event macros don't exist. I have seen quite a number designed for use with games.  For example a 'repeat click' macro, so you can go do other things while your 'game avatar' continues to work.  Or one that looks at the game display and performs some complicated action (like crafting in minecraft).  But like I said they are very carefully designed for specific tasks.

These are scripted macros, and are really the only way to implement them. It is one reason why I was interested in the very special application  "visgrep" from the "xautomation" package.  With this a macro script can take a snapshot image of the display, then search for very small sub-images to discover the exact location of a button to click or where a text box is relative to some specify image.
That way the 'macro script' can adjust itself accordingly.  The one published example I have seen using this program is  https://blog.sleeplessbeastie.eu/2013/01/21/how-to-automate-mouse-and-keyboard/

Of particular note was that "visgrep" was so specialised and simple it was a lot FASTER than a more general sub-image searcher, I have also been involved with...  ImageMagick "compare"  http://www.imagemagick.org/Usage/compare/#sub-image


If you find other macro scripts, processors, or utilities for such scripts, please let me know.


Practical examples...

The keyboard macro I have found to me most useful.   When I press  'Window-V' (Super-V) it executes
    sh -c 'xsel -b | keyboard_macro -
The script then types whatever text is in the clipboard, as if I typed it. Great when you deal with an application (like password inputs) that insist you type the text, and does not let you paste it!  I use it all the time!

Another example I have come across was a 'text box editor'.     You put you mouse pointer in a text box.  It then 'copies' the text, put it in your favorite editor, then when you exit, it replaces the modified text back into the original text box (assuming the window hasn't moved!).  I don't know how good it is as I haven't used it in a very long time, mroe of a curiosity I played with for a few hours... 
http://www.ict.griffith.edu.au/anthony/software/#edit_textbuf


  Anthony Thyssen ( System Programmer )    <A.Th...@griffith.edu.au>
 --------------------------------------------------------------------------
    Dr Basher: "Who told you that?"     Miles O'Brian: "You did!"
        "Well who am I to argue with me!!"     -- StarTrek DS9, "Visions"
 --------------------------------------------------------------------------


--
You received this message because you are subscribed to the Google Groups "xdotool-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xdotool-users+unsubscribe@googlegroups.com.
To post to this group, send email to xdotoo...@googlegroups.com.
Visit this group at https://groups.google.com/group/xdotool-users.
For more options, visit https://groups.google.com/d/optout.

G.W. Haywood

unread,
Mar 23, 2018, 6:42:34 AM3/23/18
to xdotool-users
Hi there,

On Wed, 21 Mar 2018, 'Bob C' via xdotool-users wrote:

> I want to turn on a record function and go to the editor, and perform a
> series of keystrokes, and then tell it to stop recording, and save it to a
> file, and maybe edit the file.
>
> Then I want to be able to use xdotool to playback that recording to perform
> that same sequence of keystrokes on another document.
> [...]
> Any ideas?

You probably don't want to hear this, but what you need is Emacs.

Even if you don't intend to use it as your main editor it's worth
getting to know your way around it a little. Same with Vi.

--

73,
Ged.

Bob Currey

unread,
Mar 23, 2018, 12:10:09 PM3/23/18
to 'G.W. Haywood' via xdotool-users
You are correct that I have never been able to successfully edit a file and exit gracefully with either emacs or vi. The keyboard mappings on both of those are very foreign and I've been lucky not to destroy anything the times I have been forced to use them.

Tilde is a great editor, but doesn't have keyboard macros.

Jed doesn't work with my mouse at all.

MCedit is tricky for editing multiple files, but is a close 2nd

Notepad++ is not available on linux

xmacro locks the pc

xnee i can't get to work

Autokey takes 36 mb of memory (I may need to bite the bullet when needed)

Oh well, thanks for taking time to reply

BobC

G.W. Haywood

unread,
Mar 23, 2018, 2:11:13 PM3/23/18
to xdotoo...@googlegroups.com
Hello again,

On Fri, 23 Mar 2018, 'Bob Currey' via xdotool-users wrote:

> You are correct that I have never been able to successfully edit a
> file and exit gracefully with either emacs or vi.

RTFM (1).

> The keyboard mappings on both of those are very foreign ...

I'll admit the concepts in Vi are are not exactly to my taste.

Emacs lets you define your own keyboard mappings (see (1)). The 'X'
version of Emacs can in my experience behave oddly sometimes under
certain corner-ish circumstances, but I normally avoid it. You might
want to try 'emacs-nox' or whatever your distro calls it. After using
it for decades it seems odd to me that it could cause anyone so much
pain, but then I suppose I was already very familiar with it before
there was any graphical stuff in things like Linux, so the learning
curve wasn't so steep when that came along and is now long forgotten.

Good luck.

--

73,
Ged.

G.W. Haywood

unread,
Mar 24, 2018, 6:44:24 AM3/24/18
to xdotoo...@googlegroups.com
Hello once again,

On Sat, 24 Mar 2018, bcurrey99 wrote:

> I do know how to RTFM and am aware that emacs has the ability to
> redefine keybindings, and if I could have found a set of CUA style
> keybindings already working I would have tried that route.

One command does that in Emacs: M-x cua-mode

https://www.gnu.org/software/emacs/manual/html_node/emacs/CUA-Bindings.html

I'd have thought that this was at least the basis of something useful
for your circumstances. And of course it's infinitely configurable.

> I used to have a DOS editor called Brief where I took one of their
> keyboard templates, changed it to be even more pc oriented and
> added my own macros for it. It did everything I was and am looking
> for, and was quite an editor.

I guess you could try to run Brief under DOSBox, I use it to run some
old business software (just for testing, before deployment to the real
FreeDOS machines). It seems reasonably robust and it doesn't hog all
the CPU cycles if you don't want it to.

> I just don't have the time or desire to spend that kind of effort on
> emacs and absolutely no desire to try to learn unix terminal
> keyboard layouts from the 1980s.

I don't think anyone is suggesting anything like that.

PS: I think you forgot to send your mail to the List; I grabbed your
direct mail to me from the greylist bin before it got rejected.

--

73,
Ged.

Anthony Thyssen

unread,
Mar 25, 2018, 9:36:09 PM3/25/18
to xdo...@jubileegroup.co.uk, xdotool-users
If this is for editing LOTS of files.   I do this using VI  all the time,  and I don't even use a Kerboard marco -- just copy-n-paste with the mouse!
I prepare and copy-n-pasting VI commands from a notepad of some kind.  The prepared commands include a 'go to next file', so I can do thousands of files in minutes, one click per file.

The trick is that recently, paste in VI will do a insert text only, unless you disable "bracket-paste" for your terminal window. 
To do that I add this to my .vimrc to tell it to ignore bracket paste controls when in the two command modes, but not when in insert mode.

nmap <PasteStart> <NOP>
nmap <PasteEnd>   <NOP>
cmap <PasteStart> <NOP>
cmap <PasteEnd>   <NOP>


Bob Currey

unread,
Mar 28, 2018, 5:47:14 AM3/28/18
to xdotool-users
Anthony,

I liked your scripts you posted before better than the idea of trying anything VI related.  I have run into VI screens before, and if you don't have access to a manual while doing so, it's quite an adventure.

I tried one of Ged's ideas, and over the weekend I resurected my vintage early 1990's 386 (modified to 486 eventually) lunchbox portable (from before laptops were invented), and even though it started smoking and there was a putrid smell of burning plastic, I was able to pull out the SCSI hard drive and controller, and remount them in a newer server case from 1997, and I got it booted up on DOS 6.0 (linux wasn't happy).  Then I used Norton's disk doctor to go through the diskettes I have left, and get a few good ones to work with, and I copied my utilities, including Norton Commander, the disk test parts of Norton Utilities, and my Brief editor, including all the macros and macro source, etc, etc, all to folders, then zipped each, and wrote them to the floppys, and used an old USB floppy drive I have from 2000 to copy them all to my current linux system, tested and extracted them all, and then changed the setup for a color screen (without a manual, yikes, where did it go), and brought it up under DOSbox, and lo and behold it works, keyboard macros and all, with the exception that I need to remap DOSbox's control keys so they don't conflict with the window manager or Norton Commander or Brief.  I was able to bring up 50 files and automatically edit them all, and it came up in seconds, so its not perfect, as I have 8.3 upper case filenames, but at least I now have a way to record a series of edits, save them to files and play it back automatically from hot keys for one file or many if I really need to.

Admittedly, the DOSbox and 30 yr old customized editor are probably not the best long term solution.  My thoughts at this point are to either:
1. use Autokey, that would probably just work at the price of 36 mb of memory
2. as Ged suggested spend the time to learn and use and/or remap an editor like emacs that has keyboard macros.  He is correct that I wasn't aware it had a CUA mode, I guess my Google search string wasn't good enough to bring that to light.
3. if I could get Jed working with my mouse, it would be an option, as its a "Brief clone".
4. maybe Grief or Crisp open source version might work, who knows, but they don't look to be supported, so probably not a great idea
5. or learn enough C++ (and how to debug it) to add just a "Keyboard Macro Record" feature to the Tilde editor, with just Start, Pause, and Stop functions (i.e. very basic), and get it to write to a hard coded text file, optimally that I can then execute with xdotool, or if not, maybe have an intermediate process to convert the output into a file that can be executed by xdotool. Not sure that's worth the effort, either.

Anyway, thanks everyone for the suggestions...
BobC

--
You received this message because you are subscribed to the Google Groups "xdotool-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xdotool-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages