5

The valuable keyboard automation tool xdotool does not work on Wayland. A new tool that mimicks some of the functionality of xdotool, but that works both in Xorg and Wayland, is ydotool.

ydotool is available in the Ubuntu software center as version 0.1.8-3. It the mean time, the tool has been "refactored" in the sense that it has been completely rewritten, has no external dependencies and uses a lot less memory and without dynamic memory allocation. It is therefore strongly preferred to use a current version.

Only source code is provided on github, without instructions on how to build the code and install the tool. How can we install ydotool 1.0.1. on Ubuntu?

1

1 Answer 1

3

With the advent of Wayland, automation utilities like xdotool, which are designed for Xorg, do not anymore work. ydotool is a keyboard automation tool that works independent of the display manager, i.e., it works on both Wayland and Xorg.

Following are installation instructions I tested on Ubuntu 22.04. Credits to here for the compilation instructions using cmake.

1. Prerequisites

1.1 Make sure you have the necessary tools for compilation.

# Needed for compilation
sudo apt install cmake scdoc pkg-config

1.2 In Debian based distributions, checkinstall can be used to package the compiled code into a .deb file instead of moving the compiled files directly into the system directories. That way, the custom compiled program is known in the package management system, and can easily be removed again if desired.

# For generating an installable .deb file
sudo apt install checkinstall

1.3 Optional: Install git to clone from git. Alternatively, you can download and unpack the .zip file from the github page.

# Optional: git to clone the repository instead of downloading zip
sudo apt install git

2. Downloading and compiling

2.1 Download the source code using the git tool.

git clone  https://github.com/ReimuNotMoe/ydotool

Alternatively, download and unpack the zip file from the github page

2.2 Compilation

cd ydotool ## This will be `ydotool-master` if you extracted the zip file
mkdir build && cd build
cmake ..
make -j `nproc`

3. Installation

Instead of a classical sudo make install to install the compiled files into the system directories, checkinstall can be used on Debian based systems. checkinstall creates a .deb file which then can be installed using the APT package manager. Thus, the package management system knows about the package, and the package can easily be removed again using the package manager.

3.1 Start the tool

sudo checkinstall

3.2 Accept the default answer on the prompt

The package documentation directory ./doc-pak does not exist. 
Should I create a default set of package docs?  [y]:

3.3 Enter a description for the package

Please write a description for the package.
End your description with an empty line or EOF.
>> 

for example: Keyboard automation utility - custom install

3.4 Change the name of the package to something more meaningfull: on the prompt

This package will be built according to these values: 

enter 2 to change the package name to e.g. ydotool-custom. Thus, the package will be easily recognized later, and there will be no name conflict with the Ubuntu provided package.

3.5 Again accept the default answer, n, on the prompt

Some of the files created by the installation are inside the home directory: /home

You probably don't want them to be included in the package.
Do you want me to list them?  [n]: 

3.6 However, answer y on the next question

Should I exclude them from the package? (Saying yes is a good idea)  [n]: 

although answering no and leaving these files in probably does not hurt at all.

After this, the .deb is created and automatically installed. It could be reinstalled later with the command sudo apt install <path-to-debfile>.

4. Configuration

4.1 ydotool must run a root. There are probably more modern ways to allow a user to start the utility without using sudo, but the old trick is to set the suid bit on the executable.

# Set the suid bit so ydotool can be run by any user
sudo chmod +s $(which ydotool)

4.2 With the application, a systemd service is installed. Enable and install it:

# Enable the systemd daemon, and start it
sudo systemctl enable ydotool
sudo systemctl daemon-reload
sudo service ydotool start

The daemon expects the socket through which ydotool communicates on /tmp/.ydotool_socket. When run as user, ydotool looks for /run/user/<uid>/.ydotool_socket. One could make a symbolic link to /tmp/.ydotool_socket. Alternatively, you can set a variable YDOTOOL_SOCKET to indicate the socket to use.

  • Open ~/.profile in a text editor

  • Add the line

    export YDOTOOL_SOCKET=/tmp/.ydotool_socket
    

5. Test if it works

5.1 Log out then back in to have the environment variable take effect.

5.2 Open a terminal and test with following command:

ydotool type Ubuntu

The letters "Ubuntu" should be typed before your prompt reappears.

2
  • Thank you for a clear and comprehensive answer! With your instructions, the ydotoold service doesn't automatically start when the computer is restarted. To fix this, at step 4.2, after you have created the symbolic link, instead of reloading the daemon and starting the service, you need to enable the service and start it. This single command does the job: sudo systemctl enable --now ydotool. Thank you again. yesterday
  • 1
    @PaddyLandau Thans for the feedback. I will update the instructions!
    – vanadium
    yesterday

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .