Skip to content

Instantly share code, notes, and snippets.

@cclauss
Created August 11, 2013 05:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cclauss/6203459 to your computer and use it in GitHub Desktop.
Save cclauss/6203459 to your computer and use it in GitHub Desktop.
Get and set the text content of the Mac OS X Pasteboard using pbcopy and pbpaste
#!/usr/bin/env python
# For details, in Mac OS X Terminal type: man pbcopy
import subprocess, sys
def getClipboardData(): # Only works for data types: {txt | rtf | ps}
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE)
retcode = p.wait()
data = p.stdout.read()
return data
def setClipboardData(data):
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
p.stdin.write(data)
p.stdin.close()
retcode = p.wait()
def sendTextToiOS(inText):
pass # Your Prowl code goes here!!!
def main(argv):
theText = getClipboardData()
if not theText:
print('No text found on the Mac OS X Pasteboard.')
return -1 # signal error
print('Got: ' + theText)
sendTextToiOS(theText)
return 0 # noError
if __name__ == '__main__':
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment