Skip to content

Instantly share code, notes, and snippets.

@sbp
Created July 10, 2012 12:27
Show Gist options
  • Save sbp/3082977 to your computer and use it in GitHub Desktop.
Save sbp/3082977 to your computer and use it in GitHub Desktop.
Take a screenshot on OS X and upload it to imgur using the "Anonymous" API
#!/bin/bash
# screenshottr!
# Take a screenshot on OS X and upload it to imgur using the "Anonymous" API
# Written by Sean B. Palmer
# Released under the Apache License 2.0. Viva la Libre!
# Abusest thou not this API key
API_KEY="273b7108a37679d9ac31ad5a9f1a314a"
SCREENSHOT="/tmp/$$.screenshot.png"
OUTPUT="/tmp/$$.output.json"
screencapture -Wisx "$SCREENSHOT" 2> /dev/null
curl -s -F "image=@$SCREENSHOT" -F "key=$API_KEY" \
https://api.imgur.com/2/upload.json > "$OUTPUT"
python -c "
import json
with open('$OUTPUT') as f:
# print repr(f.read())
output = json.load(f)
print output['upload']['links']['original']
print output['upload']['links']['delete_page']
"
python -c "
import sys, json
with open('$OUTPUT') as f:
output = json.load(f)
sys.stdout.write(output['upload']['links']['original'])
" | pbcopy
rm -f "$SCREENSHOT" "$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment