0

I am trying to overwrite the command Copy - Ctrl+C with the output result I have processed in my Python Script.

For eg. my script output result return this-is-a-test, and if I run paste (Ctrl+V), it should paste this-is-a-test

Is this achievable in Python context, linux environment?

dissidia
  • 1,531
  • 3
  • 23
  • 53
  • Should this be working in windows/linux env? – Dekel Jan 17 '17 at 00:27
  • Well, anyway - this is for linux: http://stackoverflow.com/questions/7606062/is-there-a-way-to-directly-send-a-python-output-to-clipboard and this is for windows: http://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python – Dekel Jan 17 '17 at 00:29
  • linux, edited in my post.. my bad! – dissidia Jan 17 '17 at 00:29
  • 1
    Possible duplicate of [Is there a way to directly send a python output to clipboard?](http://stackoverflow.com/questions/7606062/is-there-a-way-to-directly-send-a-python-output-to-clipboard) – Dekel Jan 17 '17 at 00:30
  • I tried the linux method given by NullUserException.. I got `File "/apps/Linux64/aw/maya2016/lib/python2.7/subprocess.py", line 1335, in _execute_child # raise child_exception # OSError: [Errno 2] No such file or directory # ` – dissidia Jan 17 '17 at 00:32
  • Do you have `xsel` installed? – Dekel Jan 17 '17 at 00:32
  • Unfortunately no I do not.. I am doing this from my company system in which I can't install anything.. And so I am asking if there is a pythonic way to do so – dissidia Jan 17 '17 at 00:36
  • Are you able to install python libraries? – Dekel Jan 17 '17 at 00:38
  • btw, which dist of linux you use? – Dekel Jan 17 '17 at 00:39
  • Don't think so but I can try to see if I can install. I am using Red Hat 4.4.7-4 – dissidia Jan 17 '17 at 00:42

1 Answers1

0

You can use the pyperclip library which is a cross platform and should work on windows/linux/mac.

>>> import pyperclip
>>> pyperclip.copy('The text to be copied to the clipboard.')
>>> pyperclip.paste()
'The text to be copied to the clipboard.'

If you can't install any library you can check the code (on github) and use parts of it. It might give you the solution you are looking for.

Dekel
  • 60,707
  • 10
  • 101
  • 129
  • Well, it seems that I am unable to install. I suppose to do such 'copy', I will need other libraries to do so, right? – dissidia Jan 17 '17 at 01:06
  • You should try that lib, it tries multiple copy solutions based on what the OS should support. – Dekel Jan 17 '17 at 01:16
  • Yea.. but since I am unable to install the lib, I am looking at other solutions such as pyqt etc – dissidia Jan 17 '17 at 01:38