我可以通过 Ctrl+C 复制获得视觉反馈吗?

eri*_*i0o 6 notification unity clipboard clipboard-manager

很多时候我需要多次Ctrl+ C(或Ctrl+ Insert)来复制一些东西。我会很感激视觉反馈说“已经复制了一个新东西”或类似的东西。有什么办法可以将它添加到 Ubuntu 中吗?

Byt*_*der 6

我调整了我的脚本以对此处的剪贴板更改做出反应,以便在您复制内容时显示本机通知气泡:

在此处输入图片说明

#!/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()
Run Code Online (Sandbox Code Playgroud)

将其保存在某处(例如,/usr/local/bin/clipboard-notifier您需要sudo被允许在该位置写入,或者将其放入~/bin)并使用命令使其可执行chmod +x FILENAME

我的脚本使用 Python 3 包notify2来显示本机通知气泡。默认情况下通常不安装此包,您必须先使用以下命令添加它:

sudo apt install python3-notify2
Run Code Online (Sandbox Code Playgroud)

如果你愿意,你可以修改接近脚本的开头大写变量的值,以您的需求,尤其是TITLEMAXLENGTH可能改变有用。

然后只需将它添加到您的启动应用程序,它就会在您下次登录时自动启动。您还可以从例如Unity 中的Alt+ F2HUD手动启动脚本。