deppfx
deppfx

Reputation: 751

Why does xdotool type twice ? How can I avoid it?

[Wed Aug 05 20:49:43 deppfx@localhost:~] $xdotool type password

password[Wed Aug 05 20:50:51 deppfx@localhost:~] $password

How can I avoid this ? Can someone please explain this behavior ?

Upvotes: 4

Views: 1226

Answers (4)

Anuj Falcon
Anuj Falcon

Reputation: 31

Adding to the answer above, one could add tput el1 before echo such that

xdotool type password; tput el1; echo

This will erase the unnecessary contents, creating a blank line after the previous prompt (which is also unnecessary)

[Wed Aug 05 20:49:43 deppfx@localhost:~]$ xdotool type password; tput el1; echo

[Wed Aug 05 20:49:43 deppfx@localhost:~]$ password

Upvotes: 2

林果皞
林果皞

Reputation: 7813

This thread "xdotool type duplicates" explains the reason:

That's not twice. Explaining why this appears requires a bit of detail on how shells and terminals behave.

You can observe this yourself with normal keyboard typing by running this:

% sleep 5

And while sleep is running, type "hello world" in the same terminal. When sleep exits and returns you to your shell prompt, you will see something like this:

nightfall(~) % sleep 5

hello worldnightfall(~) % hello world

What is happening is you typing into the terminal while sleep runs (or xdotool), sleep doesn't read from stdin, so when the shell is given control again it reads your keystrokes (in the input buffer) and prints them on the screen showing you what you see above.

My current workaround is add an extra echo, e.g.:

xdotool type password; echo 

which output:

[Wed Aug 05 20:49:43 deppfx@localhost:~]$ xdotool type password; echo
password
[Wed Aug 05 20:49:43 deppfx@localhost:~]$ password

This doesn't erase the previous line but at least prevent your prompt growth too long occupied by duplicated commands.

Upvotes: 1

Arash
Arash

Reputation: 314

@Wnoise is right!

But if you insist you can do this:

stty -echo && xdotool type password && stty echo

Upvotes: 3

wnoise
wnoise

Reputation: 9942

It's not actually typing twice; it's typing while it has control of the terminal, then the shell prompt returns and reformats what got typed at the terminal. Try typing into a different xterm (e.g. xdotool selectwindow type password), and you should see only one copy.

Upvotes: 1

Related Questions