Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Last active August 29, 2015 14:04
Show Gist options
  • Save alecthegeek/5e4d73a47bd682f3742a to your computer and use it in GitHub Desktop.
Save alecthegeek/5e4d73a47bd682f3742a to your computer and use it in GitHub Desktop.
CLI script to copy a file to the user's public DropBox folder and put a shortened public link in the clipboard. Inspired by @matthewmccullough and @tlberglund
#! /usr/bin/env bash
# $1 file to share
db_home=$HOME/DropBox # You need to run the DropBox client on your workstation
db_id=<999999> #Put your Dropbox ID here
if [[ -f "$1" ]] ; then
cp "$1" $db_home/Public #Only works if you have an Old Style account with magic Public directory
curl https://www.googleapis.com/urlshortener/v1/url \
-H 'Content-Type: application/json' \
-d '{"longUrl": "https://dl.dropboxusercontent.com/u/'$db_id/$(echo "${1##*/}"| gsed -e 's/ /%20/g')'"}' 2>/dev/null |
gsed -ne 's/^ *"id": "\([^"]\+\)".*$/\1/p' |pbcopy
echo $(pbpaste)
else
echo no valid source file "$1" found
fi
@alecthegeek
Copy link
Author

This works for me. If you have problems let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment