Python script to copy text to clipboard [duplicate]
On macOS, use subprocess.run
to pipe your text to pbcopy
:
import subprocess data = "hello world"subprocess.run("pbcopy", universal_newlines=True, input=data)
It will copy "hello world" to the clipboard.
Use Tkinter:
https://stackoverflow.com/a/4203897/2804197
try: from Tkinter import Tkexcept ImportError: from tkinter import Tkr = Tk()r.withdraw()r.clipboard_clear()r.clipboard_append('i can has clipboardz?')r.update() # now it stays on the clipboard after the window is closedr.destroy()
(Original author: https://stackoverflow.com/users/449571/atomizer)