If you’re on a Linux system, you can use the pyGTK library. It’s got a clipboard feature.
Here’s how to use it (code thanks to Thomas Lee):
import pygtk pygtk.require('2.0') import gtk # get the clipboard clipboard = gtk.clipboard_get() # read the clipboard text data. you can also read image and # rich text clipboard data with the # wait_for_image and wait_for_rich_text methods. text = clipboard.wait_for_text() # set the clipboard text data clipboard.set_text('Hello!') # make our data available to other applications clipboard.store()
An alternative to the GTK library is the Xsel command line program. It should work for any Linux (or Unix?) with X.
And this is how you would use it (at least according to these guys):
#Copy from the clipboard: import os s = popen('xsel').read() #Paste to the clipboard: import os os.popen('xsel', 'wb').write(s)