Skip to content

One more clipboard access method on unix #191

@unxed

Description

@unxed

xclip is rarely installed by default. If not, a helper script can be used instead, using for example python with one of commonly installed by default modules. Like this:

#!/usr/bin/env python3
import sys
import tkinter as tk

root = tk.Tk()
root.withdraw()  # hide the main window

if len(sys.argv) > 1:
    # write text to the clipboard
    text = " ".join(sys.argv[1:])
    root.clipboard_clear()
    root.clipboard_append(text)
    root.update()
    # keep the Tk window alive a little longer so X11 can persist the clipboard
    root.after(10, root.destroy)
    root.mainloop()
else:
    # read text from the clipboard
    try:
        print(root.clipboard_get())
    except tk.TclError:
        print("", end="")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions