ydotool is a command-line tool for simulating keyboard and mouse input on Linux, working on both X11 and Wayland. Unlike xdotool, it operates at the kernel level via /dev/uinput, making it display-server agnostic.
The daemon (ydotoold) must be running for ydotool commands to work.
Create the service file at ~/.config/systemd/user/ydotoold.service:
[Unit]
Description=ydotool user daemon
After=graphical-session.target
After=xdg-desktop-portal.service
PartOf=graphical-session.target
[Service]
ExecStartPre=/usr/bin/sleep 2
ExecStart=/path/to/ydotoold
ExecStartPost=/usr/bin/sleep 0.5
ExecStartPost=/usr/bin/chmod 666 /tmp/.ydotool_socket
Restart=on-failure
RestartSec=1s
[Install]
WantedBy=graphical-session.target| Directive | Purpose |
|---|---|
After=graphical-session.target |
Ensures the daemon starts after the desktop session is ready |
After=xdg-desktop-portal.service |
Waits for XDG portal (important for Wayland) |
PartOf=graphical-session.target |
Ties the service lifecycle to the graphical session |
ExecStartPre=/usr/bin/sleep 2 |
Brief delay to ensure session is fully initialized |
ExecStartPost=/usr/bin/chmod 666 /tmp/.ydotool_socket |
Makes the socket accessible to all users (required for non-root operation) |
Restart=on-failure |
Automatically restarts if the daemon crashes |
WantedBy=graphical-session.target |
Enables auto-start with graphical login |
-
Create the service directory (if it doesn't exist):
mkdir -p ~/.config/systemd/user -
Create the service file:
nano ~/.config/systemd/user/ydotoold.service # Paste the service configuration above
-
Adjust the ExecStart path to point to your
ydotooldbinary:# Find your ydotoold location which ydotoold # Update ExecStart= in the service file accordingly
-
Reload systemd and enable the service:
systemctl --user daemon-reload systemctl --user enable ydotoold.service systemctl --user start ydotoold.service -
Verify it's running:
systemctl --user status ydotoold.service
# Check if enabled at boot
systemctl --user is-enabled ydotoold
# Check current status
systemctl --user status ydotoold
# View logs
journalctl --user -u ydotooldThe chmod 666 on the socket (/tmp/.ydotool_socket) is necessary because ydotoold typically runs as your user but other processes may need to communicate with it. Without this, you may get "permission denied" errors when running ydotool commands.
- "ydotool: error: failed to connect to socket" - The daemon isn't running. Start it with
systemctl --user start ydotoold - Permission errors - Ensure the
chmodpost-start command is in place - Not starting at boot - Verify
graphical-session.targetis reached:systemctl --user list-units --type=target
This gist was generated by Claude Code. Please validate the information for your specific environment and ydotool version.