I came across this code when searching for a solution. Unfortunately my rep wasn't high enough to comment so I have started a question for help.
The code below works perfectly and does exactly what I needed it to. Problem I have is aside from the 2 obvious bits def function and call function, I am not sure what it is doing. It seems to add like a "\n"
newline to the copied string, as when I paste it it does a new line so I want to strip that out. Thanks in advance.
#import subprocess - ok
import subprocess
#define a function called copy2clip which takes 1 argument, txt.
def copy2clip(txt):
#Call CMD and echo (txt) to the clip program (which is not a python program)
cmd='echo '+txt.strip()+'|clip'
#Check that the CMD program ran ok
return subprocess.check_call(cmd, shell=True)
#call our function and pass it this string....
copy2clip('now this is on my clipboard')