很多次,我需要Ctrl+ C(或Ctrl+ Insert)多次复制的东西。我希望看到“已复制新事物”或类似内容的视觉反馈。有办法将其添加到Ubuntu吗?
我对脚本进行了调整,以从此处对剪贴板的更改做出反应,以便在您复制任何内容时都显示一个本机通知气泡:
#!/usr/bin/env python3
# Configuration:
APPNAME = "Clipboard Notifier" # an arbitrary application name
TITLE = "Clipboard modified" # the bold headline of each notification
ICON = "edit-paste" # name of the icon to show
MAXLENGTH = 100 # maximum message length
# Imports:
import gi
import signal
import notify2
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
# Set up signal handler for killing the script with Ctrl+C from terminal:
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Initialize the notifications library:
notify2.init(APPNAME)
# Callback function to handle clipboard modification events:
def callback(*args):
# Get new clipboard content:
text = clip.wait_for_text()
# Truncate long content to avoid huge notification bubbles:
body = text if len(text) < MAXLENGTH else text[:MAXLENGTH] + "..."
# Create and show notification bubble:
notify2.Notification(TITLE, body, ICON).show()
# Set up clipboard and register callback for change events
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip.connect("owner-change", callback)
# Start Gtk main loop and wait for events:
Gtk.main()
将其保存在某个位置(例如-as-但/usr/local/bin/clipboard-notifier
您需要sudo
被允许在该位置写入,或者将其放入~/bin
),并使用command使其可执行chmod +x FILENAME
。
我的脚本使用Python 3包notify2
显示本机通知气泡。默认情况下,通常不会安装此软件包,您必须先使用以下命令将其添加:
sudo apt install python3-notify2
如果你愿意,你可以修改接近脚本的开头大写变量的值,以您的需求,尤其是TITLE
与MAXLENGTH
可能改变有用。
然后只需将其添加到启动应用程序中,它将在下次登录时自动启动。您也可以从Unity中的Alt+ F2HUD手动启动脚本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句