Friday, September 09, 2016

Pastebin and the Command Line - Clipboard Access Anywhere

A couple of days ago, I setup my phone to push the clipboard to pastebin.com automatically. Now I wanted an easy way to access these pastes from the command line. Fortunately, the pastebin API is a breeze to use, and quite curl friendly.

Here's a shell script that pulls down the most recent paste:

#!/bin/bash

##
## A command line tool to pull pastes from pastebin.com
##

USER_KEY=__SAME_USER_KEY_TASKER_USES__
API_KEY=__SAME_API_KEY_TASKER_USES__
count=1


ids() {
  curl -s -d api_option=list \
       -d api_user_key=$USER_KEY \
       -d api_dev_key=$API_KEY \
       -d api_results_limit=$count \
       'http://pastebin.com/api/api_post.php' | 
    grep paste_key |
    sed -e 's|<paste_key>||' -e 's|</paste_key>||'  
}

for id in `ids` ; do
   id=`echo $id | tr -d '[\r\n]'`
   curl -s http://pastebin.com/raw/$id
done

On Windows, I can leverage clip.exe to store the output of the most recent paste into the clipboard.

  pbget | clip

Getting content from my phone's clipboard to my Desktop's clipboard is now nearly automatic, and thanks to pastebin.com is archived for 24 hours. And as a bonus, I'm not limited to accessing the phone's clipboard from a local computer. Any server with curl and a net connection can now get quick access to my phone's clipboard.

No comments:

Post a Comment