An alternative to `xdotool type`
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.
Related videos on Youtube
Minimus Heximus
Updated on September 18, 2022Comments
-
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 almost 10 yearsedited my answer
-
Minimus Heximus almost 10 yearsI could not find any command to type. add it if you know.
-
Minimus Heximus almost 10 yearsthat would be great if you add a command to type "hello" for me. the command
send "hello"
does not type. -
gokhan acar almost 10 yearsSince you were using xdotool, you are in a gui, but it would help to know what distro and desktop environments you are using.
-
user3694243 over 5 yearsproject github.com/jmetzmeier/autokey moved to github.com/autokey/autokey
-
gokhan acar over 5 years@user3694243 Thanks. I updated the answer to point to our new repo.