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 | |
# scrot -> rokket.space, by @Smallinger | |
# https://rokket.space | |
# darwin screenshot options | |
# https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/screencapture.1.html | |
SCROTARGS=(-C -s) | |
# screenshots save or delete after upload ? 1 or 0 | |
DELETE=0 | |
# change here the folder for the screenshots to save | |
FOLDER="$HOME/Desktop/.scrotrokket" | |
# create screenshot folder | |
if [[ ! -e $FOLDER ]]; then | |
mkdir $FOLDER | |
fi | |
while (( "$#" )); do | |
if [ "$1" == "--delete" ]; then | |
DELETE=1 | |
else | |
SCROTARGS+=($1) | |
fi | |
shift | |
done | |
# take the shot | |
if [[ "`uname`" == "Darwin" ]]; then | |
# assume Darwin is Mac OS X. Sorry, Darwin guys. | |
FILE="$FOLDER/scrotrokket-$(date '+%Y%m%d_%H%M%S').png" | |
screencapture ${SCROTARGS[@]} "${FILE}" | |
else | |
FILE="`scrot ${SCROTARGS[@]} -e 'echo -n $f'`" | |
fi | |
# upload it and grab the URL | |
BASE=""; TRY=0 | |
while [[ "x$BASE" == "x" ]] && [[ $TRY -lt 3 ]]; do | |
TRY=$[$TRY + 1] | |
echo "Uploading... (try $TRY)" | |
JSON="`curl -sf -F "files[]=@$FILE" https://rokket.space/upload.php`" | |
BASE="`echo "$JSON" | python -c "from __future__ import print_function;print(__import__('json').loads(__import__('sys').stdin.read())['files'][0]['url'])" 2>/dev/null`" | |
done | |
# try upload 3 times | |
if [[ $TRY -eq 3 ]]; then | |
echo "Giving up." | |
# notification... later | |
osascript -e 'display notification "Contact Administrator" with title "Upload has Canceled" subtitle "Cancel upload after 3 trys"' | |
exit | |
fi | |
URL="$BASE" | |
# copy the URL to the clipboard | |
if [[ `type -p xclip` ]]; then | |
echo "$URL" | xclip -selection clipboard | |
echo "$URL (has been copied to clipboard)" | |
elif [[ `type -p pbcopy` ]]; then | |
echo "$URL" | pbcopy | |
echo "$URL (has been copied to clipboard)" | |
osascript -e 'display notification ""with title "Upload has finished" subtitle "URL (has been copied to clipboard)"' | |
# "$(pbpaste)" save. | |
else | |
echo "$URL" | |
fi | |
if [[ $DELETE -eq 1 ]]; then | |
rm -f "${FILE}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment