I'm trying to make a script run on startup, so that I don't have to do it manually every time, with a terminal window being open constantly.
This is the script: anti-midmouse-paste.sh
#!/bin/bash
while(true)
do
echo -n | xsel -n -i
sleep 0.5
done
It is a script I found online that clears the selected copied text. It works flawlessly when I run it regularly with: sh anti-midmouse-paste.sh
However, when I've inputted the script in /etc/systemd/system using nano, it doesn't seem to work on startup (despite enabling it with sudo systemctl enable anti-midmouse-paste
), nor when i start the script using sudo systemctl start anti-midmouse-paste
. I have done chmod +x
on both the .service and the .sh file.
Here is the .service content:
[Unit]
Description=Stops middlemouse paste from working
[Service]
ExecStart=/usr/local/bin/anti-midmouse-paste.sh #in this line specify the path to the script.
Type=simple
Restart=on-failure
Restartsec=10
KillMode=process
[Install]
WantedBy=multi-user.target
And when I check sudo systemctl status anti-midmouse-paste.service
:
● anti-midmouse-paste.service - Stops middlemouse paste from working
Loaded: loaded (/etc/systemd/system/anti-midmouse-paste.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-10-15 19:59:44 CEST; 27min ago
Main PID: 889 (anti-midmouse-p)
Tasks: 2 (limit: 19018)
Memory: 2.4M
CGroup: /system.slice/anti-midmouse-paste.service
├─ 889 /bin/bash /usr/local/bin/anti-midmouse-paste.sh #in this line specify the path to the script.
└─18219 sleep 0.5
Oct 15 20:27:01 User anti-midmouse-paste.sh[18202]: xsel: Can't open display: (null)
Oct 15 20:27:01 User anti-midmouse-paste.sh[18202]: : Inappropriate ioctl for device
Oct 15 20:27:01 User anti-midmouse-paste.sh[18206]: xsel: Can't open display: (null)
Oct 15 20:27:01 User anti-midmouse-paste.sh[18206]: : Inappropriate ioctl for device
Oct 15 20:27:02 User anti-midmouse-paste.sh[18210]: xsel: Can't open display: (null)
Oct 15 20:27:02 User anti-midmouse-paste.sh[18210]: : Inappropriate ioctl for device
Oct 15 20:27:02 User anti-midmouse-paste.sh[18214]: xsel: Can't open display: (null)
Oct 15 20:27:02 User anti-midmouse-paste.sh[18214]: : Inappropriate ioctl for device
Oct 15 20:27:03 User anti-midmouse-paste.sh[18218]: xsel: Can't open display: (null)
Oct 15 20:27:03 User anti-midmouse-paste.sh[18218]: : Inappropriate ioctl for device
As you can see, it says the script loaded and that it is running. But the logs show something that I do not understand and have not managed to find anywhere. Apparently it has something to do with me using xsel
.
Hopefully someone can make sense of this and help. Thanks in advance.
In case someone finds this post in the future wanting to do the same thing, I'll edit my post with how I did.
– WhiteApe Oct 16 '21 at 08:38