Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to hit F1 and have a string with return key to be typed automatically into the terminal I am in. I do not want to do it with bash_profile because I want it to be configured locally in once place not on every server I ssh in to.

How do I do that?

share|improve this question
I suggest you use xmacro, as seen in this reply:… – roadmr Sep 13 '12 at 16:37
Better yet, tell us what you are trying to do. There are better ways to automatize things than using xmacro. – January Sep 14 '12 at 5:22

OK, the answer that I have and which works almost exactly as requested is actually surprisingly complex. You will use xmacro to record and play back key strokes.

  1. Install xmacro

    sudo apt-get install xmacro
  2. Record a macro

    xmacrorec2 > test.macro

    Now press ESC (to record the "abort" key for recording), type whatever text you want to assign and press ESC again to stop the recording. The recorded macro is now in the file test.macro; you can edit it with a text editor.

  3. Test that macro works

    cat test.macro | xmacroplay -d 0 $DISPLAY
  4. (optional, recommended) Create a script with the above commands. Save it as

    cat test.macro | xmacroplay -d 0 $DISPLAY > /dev/null 2>/dev/null

    Make it executable:

    chmod a+x
  5. A little problem remains. xmacro plays back the exact keystrokes, but if you define a shortcut, and run the script from the shortcut, the keys will be played before you release the shortcut key, as if you started typing without releasing the key. You need to prepend the following line to the test.macro file:

    KeyStrRelease F1

    which will simulate the release of the F1 key.

  6. Using keyboard preferences (you can access them through settings or by typing `gnome-control-center keyboard), create a new shortcut under "Custom shortcuts" and assign to it F1.

OK, but there is one more caveat: the F1 shortcut will now work in every application, not only the terminal. I don't know how to solve it; possibly, in the one would have to test what window has the focus first and check whether the identifier of this window is terminal.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.