This is a modified version of @Martin Thoma's answer for GTK3 . I found that the original solution led to the process not ending and my terminal freezing when I called the script. Changing the script to the next solution to the problem for me.
#!/usr/bin/python3 from gi.repository import Gtk, Gdk import sys from time import sleep class Hello(Gtk.Window): def __init__(self): super(Hello, self).__init__() clipboardText = sys.argv[1] clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text(clipboardText, -1) clipboard.store() def main(): Hello() if __name__ == "__main__": main()
You will probably want to change which client clipboardText will be bound to, in this script it is assigned to the parameter called with the script.
In a new installation of ubuntu 16.04, I found that I had to install the python-gobject package so that it worked without a module import error.
Programster Apr 25 '16 at 11:34 2016-04-25 11:34
source share