Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
# rokket.sh - puush-like functionality for rokket.space
# Get options
# Easy server changes
# ---------------------------
secure="s"
servhost="rokket.space"
uploadurl="https://rokket.space/upload.php"
returnurl="https://a.rokket.space/"
while getopts fsu: option; do
case $option in
f)ful=1 opt=1;;
s)sel=1 opt=1;;
u)upl=1 opt=1;;
*)exit
esac
done
file_name_format="Screen Shot %Y-%m-%d at %H.%M.%S.png"
file_dir="$HOME/Pictures/Screenshots"
img_filename="$(date +"$file_name_format")"
img_file="$(date +"$file_dir/$file_name_format")"
icon="$HOME/Applications/rokket/icon.png"
# Helpful error if no options are passed
# if [[ -z $opt ]]; then
# echo "please provide an option:"
# echo "-f fullscreen"
# echo "-s selection"
# echo "-u file file upload"
# exit
# fi
# Continue with selection with no options
if [[ -z $opt ]]; then
sel=1
fi
# Capture fullscreen
if [[ ! -z $ful ]]; then
screencapture "$img_file"
fi
# Provide a selection rectangle for capture
if [[ ! -z $sel ]]; then
screencapture -i -o "$img_file"
fi
# Set the file to equal the option specified
if [[ ! -z $upl ]]; then
img_file=$2
fi
# Upload it and grab the url
#echo "Uploading ${img_filename}..."
output=$(curl -f -F files[]="@$img_file" "$uploadurl")
n=0
while [[ $n -le 3 ]]; do
#printf "Try #${n}..."
if [[ "${output}" =~ \"success\":true, ]]; then
rokketfile=$(echo "$output" | grep -Eo '"url":"[A-Za-z0-9]+.*",' | sed 's/"url":"//;s/",//')
#printf 'done.\n'
break
else
#printf 'failed.\n'
((n = n +1))
fi
done
# Check if upload failed
if [[ ! $rokketfile ]]; then
growlnotify --image "$icon" --title "Rokket!" --message "Rokket cancelled!"
echo "Upload failed, removing image."
rm "$img_file"
afplay "/System/Library/Sounds/Basso.aiff"
else
# Remove temporary files
#if [[ -z $upl ]]; then
# rm -f $file
#fi
rokketfile=$( echo "$rokketfile" | grep -Eo "\w+\.png$" )
url="$returnurl$rokketfile"
# Copy url to all clipboards
echo -n "$url" | pbcopy
# Write the url to log file
echo "${img_filename} > ${url}" >> ~/Rokkets.txt
# Display notification
growlnotify --image "$icon" --title "Rokket!" --message "$url" --url "$url"
echo "Rokket! $url"
# Play sound
afplay "/System/Library/Sounds/Purr.aiff"
fi
Sign up for free to join this conversation on GitHub.
https://gist.github.com/Smallinger/9c89371b7b8d1c3607dc865b9322599e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment