An alternative to `xdotool type`

6,941

Solution 1

I've never even heard of xdotool before now, but according to it's gentoo package:

* x11-misc/xdotool
     Homepage:            http://www.semicomplete.com/projects/xdotool/
     Description:         Simulate keyboard input and mouse activity, move and resize windows

it sounds similar to what good old expect does, especially if you don't want X11:

* dev-tcltk/expect
     Homepage:            http://expect.nist.gov/
     Description:         tool for automating interactive applications

Edit: An example on how to use expect can (of course) be found on StackOverflow. Others should be available in expect's documentation and probably in the results of this search.

Wikipedia has some code examples, too. "typing" is done with the send command, while "reading" is done with expect. The manpage also hase some examples to get you started.

Solution 2

If your desktop environment is Gnome or KDE (not sure if this will work anywhere else - and no idea about Gnome 3), then AutoKey is probably exactly what you're looking for (and a lot more!)

AutoKey does a lot of what xdotool does, but lets you configure everything in a GUI. It's a full keyboard/mouse event scripting system with phrases and scripting in Python3. Find info here with installation instructions here.

Normal output from AutoKey appears to your system as if you typed it on your keyboard, so no API or other changes to your applications are necessary.

In the simplest case, you define a phrase with an abbreviation and, optionally, a hotkey. When you type the abbreviation followed by a trigger character such as enter or tab (or press the hotkey), the abbreviation is replaced by the text of your phrase. There are a number of additional options controlling exactly how this works.

If you need to get more sophisticated, you can write an AutoKey script.

AutoKey scripts are written in Python3 which means that they are only limited by you coding ability. They can do almost anything (even invoke xdotool).

The current version is 0.95. If your package manager has an older version, you would be very much better off using the PPA or installing from source.

Share:
6,941

Related videos on Youtube

Minimus Heximus
Author by

Minimus Heximus

Updated on September 18, 2022

Comments

  • Minimus Heximus
    Minimus Heximus over 1 year

    Is there an alternative to

    xdotool type "a string"
    

    It will be more useful if it is not an X11 app. Because X11 apps seem to be more vulnerable.

    Note: I will not use it in a terminal window. So echo is not an alternative to that. echo does not type. It just prints something in terminal.

  • Stefan Schmiedl
    Stefan Schmiedl almost 10 years
    edited my answer
  • Minimus Heximus
    Minimus Heximus almost 10 years
    I could not find any command to type. add it if you know.
  • Minimus Heximus
    Minimus Heximus almost 10 years
    that would be great if you add a command to type "hello" for me. the command send "hello" does not type.
  • gokhan acar
    gokhan acar almost 10 years
    Since you were using xdotool, you are in a gui, but it would help to know what distro and desktop environments you are using.
  • user3694243
    user3694243 over 5 years
  • gokhan acar
    gokhan acar over 5 years
    @user3694243 Thanks. I updated the answer to point to our new repo.