I am a new Linux user and have settled on Ubuntu 24.04.3 LTS in Wayland. In Windows, I used AutoHotKey to automate the keyboard to type repetitive text strings with a hotkey e.g. pressing Alt+E to type my@email.com

I believe the solution in Linux is to install an application like dotool or ydotool and then create a custom shortcut command. The problem is I cannot get dotool and ydotool to work. I’ll document the issues I’m having with ydotool as there seems to be more awareness and support for this application.

I am following the instillation instructions here:

https://askubuntu.com/questions/1413829/how-can-i-install-and-use-the-latest-ydotool-keyboard-automation-tool-working-o

Everything seems to go fine until I get to this step and get the following error:

sudo systemctl enable ydotoold

Failed to enable unit: Unit file ydotoold.service does not exist.

I came across this issue which suggests it could be a permissions issue on /dev/uinput and tried to the solution provided in that post but I still can’t enable ydotoold after a reboot.

Running this command works:

ydotoold --version

v1.0.4-38-g708e96f

But I am stuck here and not sure how to troubleshoot or progress further. Any help would be appreciated, thank you!

  • med@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    2
    ·
    3 days ago

    Oh, oh I know this one!

    If your keyboard shortcut contains control characters, it will be interpreting the keypresses with the control characters you’re holding for the shortcut. Alt+a super+b etc.

    Some keyboard shortcuts trigger on press, they can also trigger on release. This is why you need the sleep statement, to give you time to release the keys before it starts typing. You want the shortcuts to trigger after release.

    I can set the difference in my window manager, but I’m not sure about doing it in (GNOME?) Ubuntu. Even assuming you can set the shortcut to only run on release, you still need to let go of all the keys instantly, so chaining with sleep is probably the best approach.

    Chaining bash sleep and ydotool works for me in my window manager. Consider using “&&” instead of “;” to run the ydotool type command. Whatever is written after the “&&” only executes if the previous command (sleep 2) succeeds. The “;” might be interpreted by the keyboard shortcut system as an end of the statement:

    sleep 2 && ydotool type abcde12345

    Or perhaps the shortcut system is just executing the programs, not necessarily through a bash shell. In that case we would need to actually run bash to use its sleep function and the “;” or “&&” bit. Wrapping the lot in a bash command might look like this:

    bash -c "sleep 2 && ydotool type abcde12345"

    Assuming that doesn’t work, I see nothing wrong with running a script to do it. You just need to get past whatever in the shortcut system is cutting off the command after the sleep statement.

    Running ydotoold at user level is preferred and recommended. It keeps it inside your user context, which is better for security.

    • DarkSpectrum@lemmy.worldOP
      link
      fedilink
      arrow-up
      1
      ·
      2 days ago

      This worked for me:

      bash -c "sleep 2 && ydotool type abcde12345"

      Thank you! I couldn’t find any good instructions for the Command field of custom keyboard shortcuts.