Skip to content

Instantly share code, notes, and snippets.

@ildus
Created May 8, 2017 07:47
Show Gist options
  • Save ildus/e87b76bb66fbede3e4beaed922a6512b to your computer and use it in GitHub Desktop.
Save ildus/e87b76bb66fbede3e4beaed922a6512b to your computer and use it in GitHub Desktop.
script to copy screenshot to dropbox and get a link
#!/usr/bin/env bash
DOPDIR='/images'
ACCESS_TOKEN='<token>'
# generate random name
matrix='abcdefghijklmnopqrstuvwxyz'
length=20
while [ "${n:=1}" -le "$length" ]
do
tempfn="$tempfn${matrix:$(($RANDOM%${#matrix})):1}"
let n+=1
done
filename=$tempfn'.'${1##*.}
remotename=$DOPDIR'/'$filename
tmpname='/'tmp'/'$filename
if [ -e "$1" ]
then
cp -f "$1" "$tmpname"
out1=`curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Dropbox-API-Arg: {\"path\": \"$remotename\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @$tmpname`
out=`curl -X POST https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"path\": \"$remotename\",\"settings\": {\"requested_visibility\": \"public\"}}"`
link=`echo -n $out | grep -oP '"url": "\K.*?[^"](?=",)' | xargs`
echo -n "$link" | xsel -b -i
#notify-send -i go-down "Dropbox" "Link to screenshot copied to clipboard"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment