Sending Your Clipboard Across The Internet

I've been working on some components of Utopiaprojekt this morning and run across the idea of sending the contents of the clipboard across the internet. So, after tooling around for a few minutes, I wrote up a working example using Python on OS X.

So, click on Read More for more information on how I did it.

The example will grab whatever text that is in the Pasteboard (analogous to the Clipboard in Windows), transform it to Base64 encoding (which is pretty much the gold standard for encoding text across the internet) and then ship the text off to a server for processing.

Once there, I wrote up a small PHP page which will decode the text, and then write the results to a file on the local server for viewing. Of course, after decoding you can put the text in a database, write it to files, whatever you need it to do. This is just an exercise in getting it from point A to point B without mangling it too bad.

I've left a lot of print statements in here and there so you can see the information transform as it occurs. Note that it only works on OS X at the moment.

Enjoy!

tom

Client Side


import subprocess, base64, urllib

p = subprocess.Popen(“pbpaste”, stdout=subprocess.PIPE)
mytext = p.stdout.read()
encoded = base64.b64encode(mytext)
decoded = base64.b64decode(encoded)

print “mytext is:”,mytext , “n”
print “encoded is:”,encoded , “n”
print “decoded is:”,decoded , “n”

print “sending the data up to web server n”

myurl = 'http://example.com/test/decode.php?thought=' + encoded

urllib.urlopen(myurl)

Server Side


<?
$thought = $_GET['thought'];

$stringData = base64_decode($thought);

$myFile = “testFile.txt”;
$fh = fopen($myFile, 'w') or die(“can't open file”);
fwrite($fh, $stringData);
fclose($fh);

?>

Comments are closed.