我试图在启动时运行一个脚本,这样我就不必每次都手动运行,因为终端窗口一直在打开。
This是脚本: anti-midmouse-paste.sh
#!/bin/bash
while(true)
do
echo -n | xsel -n -i
sleep 0.5
done这是我在网上找到的一个脚本,它清除了所选的复制文本。当我定期使用:sh anti-midmouse-paste.sh运行它时,它运行得完美无缺。
但是,当我使用nano在/etc/systemd/system中输入脚本时,它似乎在启动时不起作用(尽管使用sudo systemctl enable anti-midmouse-paste启用了它),或者当我使用sudo systemctl start anti-midmouse-paste启动脚本时也是如此。我在.service和.sh文件上都做了.sh。
Here是.service内容:
[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.targetAnd当我检查 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如您所见,它表示脚本已加载并正在运行。但是日志显示了一些我不明白的东西,也没有找到任何地方。显然,这与我使用xsel有关。
希望有人能理解这件事并提供帮助。提前谢谢。
发布于 2021-10-16 14:35:10
这是关于如何在启动时自动禁用Ubuntu上的中间鼠标粘贴的指南。这之前是一个请求帮助的帖子,但现在我已经学会了如何去做,我会分享我是如何做到的。
这使用了我在另一篇文章中找到的脚本,该脚本清除鼠标中间按钮的剪贴板,这样当您单击滚动轮时它就不会被粘贴。这里的Found: https://askubuntu.com/a/4644/1481518。功劳归于他。
Step 0:安装xsel (X选择的操作工具):sudo apt-get install xsel。一旦安装了xsel,就可以继续。
Step 1:创建脚本-打开您选择的文本编辑器,并键入以下代码:
#!/bin/bash
while(true)
do
echo -n | xsel -n -i
sleep 0.5
done将文件保存为anti-midmouse-paste.sh (名称可以是其他内容,但请确保添加.sh)。
还使脚本文件可执行:chmod +x /path/to/file/anti-midmouse-paste.sh
Step 2:现在我们已经创建了脚本,是时候让它在启动计算机时运行了。
打开文本编辑器的另一个窗口,并粘贴到以下内容中:
[Desktop Entry]
Type=Application
Name=Anti Midmouse Paste
Exec="/path/to/the/script/anti-midmouse-paste.sh" "--no-window"
X-GNOME-Autostart-enabled=true请确保为Exec=输入正确的路径。
并在~/.config/autostart/中将该文件保存为anti-midmouse-paste.desktop (同样,名称并不重要,但请确保它以.desktop结尾)
If您找不到 .config it是因为它是一个“隐藏”目录。要使其显示,请按 Ctrl + H and所有隐藏目录和文件将显示。
Step 4:您完成了。
现在,每当您启动您的计算机,脚本应该运行,您将不再粘贴选定的文本与您的中鼠标按钮。
BONUS提示:
该脚本清除您选择的文本应用程序,如文本编辑器和终端。
为选择文本而延迟删除(如果要复制或擦除文本),可以做的是将.sh文件中的D15更改为更高的值。这个数字以秒为单位。
https://askubuntu.com/questions/1369461
复制相似问题