Autocutsel and an Introduction to Systemd User Services
techThis post shows how to run autocutsel as a systemd user service
to keep X11 clipboards in sync.
X11 has two kinds of copy/paste buffers, namely the primary selection and the clipboard selection. The primary selection is invoked when highlighting text and with the middle mouse button while the clipboard selection uses Ctrl+C and Ctrl+V.
If you wish to keep both buffers in sync, you can use the
autocutsel daemon
to do just that, effectively merging the two buffers.
User Service
I used to just start autocutsel with my window manager, but there is
a more clean solution, systemd user services. User services are like
regular system-wide services, but they are only started when the
associated user is logged in and kept running until all sessions of
that users are closed.
-
As with regular
systemdservices, we need a service file.[Unit] Description=Autocutsel [Service] Type = forking Restart = on-failure RestartSec = 10 ExecStartPre = /usr/bin/autocutsel -fork ExecStart = /usr/bin/autocutsel -selection PRIMARY -fork [Install] WantedBy=default.targetUser service file go into the
~/.config/systemd/userdirectory. We will save above service file as~/.config/systemd/user/autocutsel.service -
To control user services, use
systemctllike usual, but with the--userflag. After savingautocutsel.service, first reload the database of services withsystemctl --user daemon-reloadand then enable the service
systemctl --user enable autocutsel -
Log out and back on again.
autocutselshould be running and keeping your clipboards in sync.
systemd will make sure that only one instance of the service is
running at a time and restart the daemon if it crashes.