hacks.moe

GitHub | Gitlab | Feed | Privacy Policy | Contact & Impressum

Autocutsel and an Introduction to Systemd User Services

This 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.

  1. As with regular systemd services, we need a service file.

    [Unit]
    Description=Autocutsel
    
    [Service]
    Type = forking
    Restart = always
    RestartSec = 10
    ExecStartPre = /usr/bin/autocutsel -fork
    ExecStart = /usr/bin/autocutsel -selection PRIMARY -fork
    
    [Install]
    WantedBy=session.target
    

    User service file go into the ~/config/systemd/user directory. We will save above service file as

    ~/.config/systemd/user/autocutsel.service
    
  2. To control user services, use systemctl like usual, but with the --user flag. After saving autocutsel.service, first reload the database of services with

    systemctl --user daemon-reload
    

    and then enable the service

    systemctl --user enable autocutsel
    
  3. Log out and back on again. autocutsel should 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.

The Tip of the Tongue

Lo-lee-ta: the tip of the tongue that goes right up the lip, down the throat to tap, at the lip. Lo-lee: the top of the tongue going down to the top of the teeth. Lo-ler-sa: to go into the mouth. Lo-ll: to drink, to swallow a cup. Lo-ll: to drink. Lo-lle: to drink and forget about it. Lo-lle-sa: to drink and forget about it again. Lo-lle-sa: to drink and forget about it to be sure. Lo-lle-sa. To drink and forget about it, that means to forget. To drink and forget about it: that means to drink when you forget it. Lo-ll-la: to drink and forget about everything, that's the way a man should drink, to the end in the mouth. Lo-ll-la: To drink and forget about everything, that is.

A computer wrote this.