Stop middle mouse pasting / startup shell script

Hi I'm pretty new to Linux, but I'm really struggling with the function middle mouse click paste since I paste my passwords all over the place. I tried using gnome tweaks, but the setting doesn't seem to work at all. I've tried various methods online but mostly cant use them since my lack of knowledge of linux. After searching the web for the past two hours, I've found the following script to work pretty well:

while true; do
    xsel -fin </dev/null

But I would have to run this every time on startup in the terminal manually and would not be able to close the terminal since it would kill the script. I've tried to run it on startup but have not managed to do so, mostly because the solutions dont seem to account for people who lack the knowledge (like myself).
I would be really appreciative if someone could give me a solution with a dummie step-by-step guide.

Selecting the middle click paste in Tweaks should actually work, does with me.

Honestly not sure at, why it doesn't work with you.

Apart from that, getting used to pasting with ctrl+v is pretty fast, too, if that is something you wanna try.

Thanks for your reply.

Im also not really sure why gnome tweaks doesnt work but there seem to be other people with the same issue. Im used to pasting with ctrl+v hence why I have opened this thread. I use ctrl+v all the time but never middle mouse paste because I use it for scrolling. Its really irritating pasting all my clipboard stuff all over the place so this is why I want to remove this function of it specifically.

You can rearrange that script into a one-line script and put it as an entry in 'Startup Applications'. That way, it's run every time you boot.

Or in Terminal:

gsettings set org.gnome.desktop.interface gtk-enable-primary-paste false

How would I have to paste it rearranged into the startup application? I tried it without rearranging and it didnt work. Or is your terminal command the solution you meant for pasting it into the startup?

Two different solutions:

  1. Rearrange the script and put it into 'Startup Applications'.

You'd open 'Startup Applications', click the 'Add' button, then provide a name (any name you want... something like 'Middle Click-Paste Negate' or similar would work), paste the one-line bash code into the 'Command' line, then provide a comment so you remember what that code does.

  1. In Terminal, enter:
    gsettings set org.gnome.desktop.interface gtk-enable-primary-paste false
    ... and that should disable middle-click pasting, unless you've got an unusual mouse setup (some Logitech mouse with several buttons, for instance).
1 Like

Thank you for your post. Sadly the first nor the second option works. I do have a Logitech mouse tho (Logitech Wireless pro)

Edit: I also tried running the .sh file via a terminal command in the autostart application but that also didnt work even tho when I put the command into the terminal it works without any problems. I think Im understanding something wrong here but cant really figure out where I understand something wrong. Never worked with .sh files so that might also be some issue.

Middle-click paste works for me on Debian 12, but I can't get it to work on ZorinOS though it may be because it's a virtual machine.

However, I would propose to you that you use a password manager. The idea behind a password manager is pretty simple and is exactly what it sounds like. All you have to do is remember a single master password, and from there you can do things like auto-type passwords where needed. I also use it for other types of credentials, notes and generate strong passwords easily.

If you prefer to keep your passwords database file locally and be responsible to maintain it across devices and appropriately backed up, you can use something like KeePassXC.
On the other hand if you prefer to have it synchronized and all of this handeld for you I'd recommend Bitwarden.

Middle-click paste works, just tried :smirk:

Both those are good - never used either myself. 1Password seems to be a top ranker recently - not free though. 14-day trial, then you gotta pay..

Is it from a mouse or touchpad? For my touchpad it's a 3-finger click, I think Gestures has some settings for multi-click options.

Maybe toggle the setting on / off - like a reboot, heh. Sometimes I have to disable / enable some toggles before they change.

1 Like

You might try using xinput list to figure out the middle button on the mouse, then remapping it to something else (or nothing else).

On my machine, it shows the touchpad (I don't have a mouse) as ID 13.

Now, my touchpad doesn't have a middle button, but if it did, I could remap it via:

xinput set-button-map 13 2 0

We're setting the button map for device ID 13, button 2 (middle click) to null (0). You could set it to 1 to emulate left-click, or 3 to emulate right-click, as well.


I got it working by using chmod -x (which I didnt know I needed to do until now). After that the script could be executed. Now I feel kinda dumb for not realising this earlier but thanks everyone for the help! :smiley:

1 Like

I marked this last post as the solution as the way I read this, I believe you are referring to your script in the O.P.

1 Like

Yes I got it working with the script I posted at the start. Thanks for marking the post, will do it myself in the future!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.