Skip to content

Instantly share code, notes, and snippets.

@banister
Created January 23, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banister/455340addabcb7eecaac1143f9d9b86c to your computer and use it in GitHub Desktop.
Save banister/455340addabcb7eecaac1143f9d9b86c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -x
CLIENT_ID=<REDACTED>
LOG_FILE=~/.image_uploader.log
touch $LOG_FILE
# folder to watch
SCREENSHOT_FOLDER=/home/user/Pictures/screenshots
created_file() {
inotifywait -e create $SCREENSHOT_FOLDER --format "%f"
}
upload_to_imgur() {
curl -vvv --fail --request POST --header "authorization: Client-ID ${CLIENT_ID}" \
--header 'content-type: multipart/form-data;' \
-F "image=@${1}" "https://api.imgur.com/3/image" | jq '.data.link'
}
dialog() {
zenity --info --text="$1"
}
while true; do
screenshot_file=$(created_file)
if [[ $screenshot_file =~ "png" ]]; then
image_link=$(upload_to_imgur "${SCREENSHOT_FOLDER}/${screenshot_file}")
if [ $? -eq 0 ]; then
dialog "Screenshot upload: $image_link saved to clipboard"
echo $image_link | xsel --clipboard
else
dialog "Something went wrong $(tail -1 $LOG_FILE)"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment