Created
January 23, 2018 15:09
-
-
Save banister/455340addabcb7eecaac1143f9d9b86c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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