I just need a python script that copies text to the clipboard.
After the script gets executed i need the output of the text to be pasted to another source. Is it possible to write a python script that does this job?
I just need a python script that copies text to the clipboard.
After the script gets executed i need the output of the text to be pasted to another source. Is it possible to write a python script that does this job?
Pyperclip seems to be up to the task.
One more answer to improve on: https://stackoverflow.com/a/4203897/2804197 and https://stackoverflow.com/a/25476462/1338797 (Tkinter).
Tkinter is nice, because it's either included with Python (Windows) or easy to install (Linux), and thus requires little dependencies for the end user.
Here I have a "full-blown" example, which copies the arguments or the standard input, to clipboard, and - when not on Windows - waits for the user to close the application:
This showcases:
raw_input
andprint()
compatibilityTo use native Python directories, use:
on Mac, instead:
Then use:
to call the function.
This is an altered version of @Martin Thoma's answer for GTK3. I found that the original solution resulted in the process never ending and my terminal hung when I called the script. Changing the script to the following resolved the issue for me.
You will probably want to change what clipboardText gets assigned to, in this script it is assigned to the parameter that the script is called with.
On a fresh ubuntu 16.04 installation, I found that I had to install the
python-gobject
package for it to work without a module import error.Use Tkinter:
https://stackoverflow.com/a/4203897/2804197
(Original author: https://stackoverflow.com/users/449571/atomizer)