This is a guide on how to disable Middle Mouse Paste on Ubuntu automatically on startup. It was previously a post asking for help, but now that I have learned how to do it, I will share how I did it.
This uses a script I found in another post that clears the clipboard for your middle-mouse button, so that it doesn't get pasted when you click the scroll wheel. Found here: https://askubuntu.com/a/4644/1481518. Credit goes to him.
Step 0: Install xsel
(Tool for manipulation of the X selection): sudo apt-get install xsel
. Once you have installed xsel, you can continue.
Step 1: Create the script - Open up your text editor of choice, and type in the following code:
#!/bin/bash
while(true)
do
echo -n | xsel -n -i
sleep 0.5
done
Save the file as anti-midmouse-paste.sh
(the name can be something else but make sure to add the .sh
).
Also make the script file executable: chmod +x /path/to/file/anti-midmouse-paste.sh
Step 2: Now that we have created the script, it's time to make it run whenever we boot up our computer.
Open up another window of your text editor, and paste in the following:
[Desktop Entry]
Type=Application
Name=Anti Midmouse Paste
Exec="/path/to/the/script/anti-midmouse-paste.sh" "--no-window"
X-GNOME-Autostart-enabled=true
Make sure you enter the correct path for the Exec=
.
And save this file in ~/.config/autostart/
as anti-midmouse-paste.desktop
(again, the name doesn't matter but make sure it ends with .desktop
)
If you can't find .config
it is because it's a "hidden" directory. To make it show, press Ctrl + H
and all hidden directories and files will show.
Step 4: You're done.
Now whenever you boot up your computer, the script should run and you will no longer paste selected text with your middle-mouse button.
BONUS TIP:
The script clears your selection of text for apps such as Text Editor and Terminal.
What you can do to delay the deletion for selection of text (if you want to copy or erase text), is to change sleep 0.5
in your .sh
file to a higher value. The number is in seconds.