Last active
June 16, 2020 19:52
-
-
Save connorworley/b92fd9f08d5540c3040face74bbfd17f 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
#!/bin/bash | |
api_key="redacted" | |
screenshot_dir=$(defaults read com.apple.screencapture location) | |
if [[ -z $(command -v fswatch) ]]; then | |
echo "Could not find fswatch, exiting" | |
exit | |
fi | |
if [[ -z $(command -v jq) ]]; then | |
echo "Could not find jq, exiting" | |
exit | |
fi | |
notifier="terminal-notifier" | |
if [[ -z $(command -v terminal-notifier) ]]; then | |
if [[ -x "/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier" ]]; then | |
$notifier="/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier" | |
else | |
echo "Could not find terminal-notifier, exiting" | |
exit | |
fi | |
fi | |
# format is flags newline path newline | |
fswatch --format "%f%n%p%n" "$screenshot_dir" | while read flags | |
do | |
read file | |
# osx renames and changes attributes at the same time when saving screenshots | |
if [[ "$flags" == "Renamed AttributeModified IsFile" ]]; then | |
$notifier -title "Pshuu?" \ | |
-message "Starting your upload..." | |
response=$(curl --silent \ | |
-F "f=@$file;type=image/png" \ | |
-F "k=$api_key" \ | |
"https://pshuu.moe/upload") | |
share_url=$(echo $response | jq --raw-output ".share_url") | |
if [[ -n "$share_url" ]]; then | |
$notifier -title "Pshuu~" \ | |
-message "Your upload is ready at $share_url" \ | |
-sound default \ | |
-open "$share_url" | |
else | |
$notifier -title "Pshuu!!!" \ | |
-message "Something went wrong!" \ | |
-sound default | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment