How to use xmacro on Ubuntu

I just had a situation where I had to do the same copy and paste job in a browser a few hundred times, so it was the perfect opportunity to look into a desktop macro recorder/player. I came across xmacro which records X11 events and lets you play them back later, and it worked perfectly after I figured out how to use it.

First, just install it with:

sudo apt-get install xmacro

Then you’re going to record your macro to a text file. Do this using:

xmacrorec2 > yourfile.txt

This will bring up a prompt that will let you tell xmacro a key to use to “exit” or stop recording. Just hit any key that you know that you will not be hitting during recording itself (I used esc).

Now you’re recording, so do whatever it is that you want to automate, and then hit your exit key (in my case, esc).

To play it back, just run it using the text file like so:

xmacroplay "$DISPLAY" < yourfile.txt

The "$DISPLAY" argument just tells xmacro to use your current display. This is not an optional argument, and if you leave it out, you’ll get errors.