xdotool type takes ages and causes entire desktop to freeze
Asked Answered
D

4

8

I've been using xdotool type in the past only to type a shrugface on shortcut using xdotool type '¯\_(ツ)_/¯'. That works, but always takes quite a long time and causes the entire desktop to freeze (entirely, not just input) for a few seconds. Didn't bother me much though.

Now I need a way to read things from a file, manipulate that, and type it out. I wanted to use xdotool for that task like this:

while read URL; do
    xdotool type "!play $URL" && sleep 1 && xdotool key Return && sleep 1
done < <(mycommand)

The mycommand put out around 20 lines of URLs. Once I ran the script my desktop (gnome3.26, archlinux) freezed entirely. I SSHd into the machine killing the bash process (successfully), but that didn't do anything to the frozen state. Ten minutes later it worked again, the command did run (as in, xdotool typed everything correctly as expected) but I had to restart the X server since my mouse wasn't working anymore.

I need a way to type automated like xdotool type does but without this freezing behaviour. The best case would be a tool that types the whole text I pass pretty much instantly. I thought of a solution implementing xclip and then just simulating the key presses for paste and enter, but I think there has to be a better solution.

This issue with xdotool has been present for me for around two years now (always been on gnome + archlinux), until now I never needed it for more than a shrugface though. I'm guessing it's not just a bug in the version I use because of that. Just for completeness:

$ xdotool --version xdotool version 3.20160805.1

Davie answered 30/12, 2017 at 21:28 Comment(3)
This Q is not about programming as defined for StackOverflow. It may be more appropriate on superuser.com or another StackExchange site. Use the flag link at the bottom of your Q and ask the moderator to move it. Please don't post the same Q on 2 different sites. Please read stackoverflow.com/help/on-topic , stackoverflow.com/help/how-to-ask , stackoverflow.com/help/dont-ask and stackoverflow.com/help/mcve before posting more Qs here. GoodLuckPsychoneurotic
I think it is appropriate on StackOverflow since I need a way to do it programatically. I need this kind of automation to be controlled using bash.Davie
This is a problem for GNOME. I had enough of this while developing my own input method (that does not utilize any english like ibus/fcitx/gcim/scim...). xdotool type and xdotool key could kill GNOME for me, and it's still not fixed and I don't think it will ever be fixed. I just gave up and proceed to manipulate clipboard and sending low level ctrl+v to type texts.Lotson
N
1

I faced the same problem on Xubuntu, so it's not just a GNOME's problem. It looks like the problem is somewhere in the interaction between xserver, proprietary nvidia driver and some compositing managers.

In Xubuntu I solved this issue by disable compositor (Settings Manager > Window Manager Tweaks > Compositor). As a result, tearing began, which is partially treated by this command (added in autostart): nvidia-settings --assign CurrentMetaMode="1920x1080 +0+0 { ForceCompositionPipeline = On }".

Theoretically you can solve this issue by changing video driver or switching from X to Wayland (and from xdotool to ydotool).

Novelize answered 2/2, 2021 at 1:36 Comment(0)
C
1

I found that it's a bug from xdotool:

https://github.com/jordansissel/xdotool/issues/281

I suggest you to go to something else, this will do exactly what you want without any delay :

https://github.com/autokey/autokey

After instalation you can define a shortcut or an abreviation to type your phrase.

Here I defined alt+z to trigger what you want And there is also "pl + an indentation" that will trigger it

enter image description here

Castigate answered 3/2, 2021 at 11:41 Comment(0)
C
0

I investigate on this because it's also a problem for me and I found that :

When you type only 10 char :

18:29:25 date +%s%N ; echo -; xdotool type "0123456789" ; echo - ;  date +%s%N
1612286985355706637

0123456789
1612286985498079368

You are in the dark for 0.142372864 sec

But when you type 100 char :

18:27:12 date +%s%N ; echo -; xdotool type "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" ; echo - ;  date +%s%N
1612286840678952107

0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1612286841733910300

You are in the dark for 1,054958080 sec

So my best guess is that when you use type, each char are typed one by one increasing the time.

xdotool type --delay 0 "long_sentence"

Seems to improve a little but not when used in an alias

Castigate answered 2/2, 2021 at 17:38 Comment(0)
D
0

As a workaround, you can copy the text to clipboard and paste it instead of typing:

# Hangs with long text and text with special characters:
xdotool type "$1"

# Does not hang:
echo "$1" | xclip -sel primary    # for use with some shared clipboards (e.g. Remmina) 
echo "$1" | xclip -sel clipboard  # for use with local OS clipboard
xdotool key Shift+Insert
Dermatoglyphics answered 20/4, 2023 at 20:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.