Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Last active Aug 29, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@alecthegeek alecthegeek commented Jul 24, 2014

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