Skip to content

Instantly share code, notes, and snippets.

@drwahl
Created February 16, 2016 16:18
Show Gist options
  • Save drwahl/b0274d7d4082072a5d6a to your computer and use it in GitHub Desktop.
Save drwahl/b0274d7d4082072a5d6a to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script is intended to be bound to your printscreen button and take a
# screenshot with scrot. The resulting screenshot should land in a folder
# that is synced with the ownlcoud client. If all goes well, a public link to
# the screenshot will be copied into your clipboard, making it super easy to
# share screenshots.
# Requirements:
# ocsharetools: https://github.com/Azelphur/ownCloud-share-tools
# USERNAME: environment variable containing your owncloud username
# PASSWORD: environment variable containing your owncloud password
#
# Modify the following variables to match your environment:
timeout=15 # time (in seconds) to wait for file to upload
synclogfile=~/ownCloud/.owncloudsync.log
screenshotdir=~/ownCloud/screenshots
owncloudurl="http://oc.drwahl.me/"
if [ "$1" = "-s" ]; then
cmd="scrot -s"
elif [ "$1" = "" ]; then
cmd="scrot"
else
echo "Error: invalid argument"
exit 1
fi
timestamp=$(date +"%Y-%m-%d-%H-%M-%S")
filename="${timestamp}_scrot.png"
$cmd ${screenshotdir}/${filename}
while [[ `tail $synclogfile | grep -c ${filename}` -eq 0 ]]; do
if [[ "$timeout" -eq 0 ]]; then
exit 1
else
timeout=$((timeout-1))
sleep 1
fi
done
share=$(ocsharetools --user "$USERNAME" --password "$PASSWORD" --url "${owncloudurl}" create --path "/screenshots/${filename}" --share-type=3 )
shareid=$(echo $share | cut -d'=' -f3 | cut -d' ' -f1)
sharelink="${owncloudurl}index.php/s/${shareid}"
echo $sharelink | xclip -selection c
notify-send --icon=gtk-info 'Screenshot Copied' 'The screenshot was copied to OwnCloud and saved into your clipboard'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment