I have a very simple script in python which generates a sentence.
For simplicity let's say I have :
var = "hello world"
I want to be able to paste (cmdV) the string, directly after running the script.
Any ideas?
You could use NSPasteboard from AppKit
def sendToClipBoard(string):
from AppKit import NSPasteboard,NSObject,NSStringPboardType
pasteboard = NSPasteboard.generalPasteboard()
emptyOwner = NSObject.alloc().init()
pasteboard.declareTypes_owner_([NSStringPboardType], emptyOwner)
pasteboard.setString_forType_(string, NSStringPboardType)
Code copied from Notestoself
You could call the pbcopy
command from within your script. For example:
from subprocess import call
var = "Hello world!"
cmd = 'echo "%s" | pbcopy' % var
call([cmd], shell=True)