clipboard — Copy and paste

The clipboard module defines two simple functions to read and write to the text clipboard (a.k.a. pasteboard) on iOS.


#Convert clipboard to uppercase/lowercase
import clipboard
text = clipboard.get()
if text == '':
    print 'No text in clipboard'
    uppercase = text.upper()
    if uppercase != text:
        new_clip = uppercase
        #already uppercase, convert to lowercase
        new_clip = text.lower()
    print new_clip

Functions in the clipboard module:


Returns the clipboard’s content as a unicode string.


Sets the clipboard’s content to a new string or unicode string.


Return an image from the clipboard as a PIL Image.

If there are multiple images in the clipboard, the idx parameter can be used to get an image at a given index. If the index is >= the number of images in the clipboard, None is returned.

clipboard.set_image(image, format='png', jpeg_quality=0.75)

Store a given PIL Image in the clipboard.

The format parameter can be ‘png’ or ‘jpeg’.

jpeg_quality is ignored if format is ‘png’, otherwise, it should be a float between 0.0 and 1.0.