Ubuntu macros

The macro feature of Notepad++ was really useful. On Ubuntu I've had to do without Notepad++, and anyway it would be better to have something that works inn any program. I've found/made something today, and since StackOverflow locks all questions about such things, I'll post it here.

First, install xmacro using sudo apt-get install -y xmacro. The basic commands are xmacrorec2 > "$macrofile" and xmacroplay "$DISPLAY" < "$macrofile". I've made a few small improvements:

  • Assigned hotkeys so I can use it in any program more conveniently and without recording alt+tab.
  • Include ESC as the decault termination key so it doesn't need to be set each time.
  • Increase the playback speed, since letters got mixed up if I played back several times in succession.
  • Send desktop notifications upon start, completion and playback, but only send playback ones if there isn't one already (or you'll be getting the whole queue of them for several minutes after completion).
  • Prevent a recording from starting if there's already one running.
  • Add a timeout (of 2.5 min) on recording so you don't accidentally leave it running and record your password.

It's simple to get started:

  1. Copy the record and playback files from the repository.
  2. In the dash menu find Keyboard, then click Shortcuts and select Custom Shortcuts.
  3. Click +, enter a name and enter the command bash /path/macro_record.sh. Repeat for playback.
  4. Click the shortcut area where it says "Disabled" and assign your shortcut, e.g. F9 and F10.
  5. Profit!
Go ahead and test it! Open a terminal (ctrl+alt+T) and start recording a macro (F9) (you should see a notification). Type some harmless command like echo "hello world!", then press the ESC key (another notification should appear). [You might have to press spacebar (nothing happens) at this point because ESC eats the next keypress]. Now you can press F10 a whole bunch of times to greet the world with appropriate enthusiasm!


Topics: #coding #tools #ubuntu #bash



Macro locks have been made more reliable, to prevent any 'start recording' events being captured by record and causing a loop

You need to be logged in to comment.