Screenshot Sharing Script for Mac OS

I recently wanted to move away from commercial screenshot sharing tools (I was using Jing), so I decided to create a script that takes screenshots, allows you to annotate them, then uploads them to my webhost. The host I use is Digital Ocean and I use sftp to upload the image. Here’s the script:

#! /bin/bash

filename=`date +%Y%m%d%I%M%S`;
filename+='_';
filename+=`openssl rand -hex 16`;
filename+='.png';
host="myhost.com"; # change to your host
domain="screens.host.com/subdir"; # this could be the same as host above for you

screencapture -i $filename;
printf "\nHit enter when you are done editing image in Preview. Don't forget to save it first (cmd+s).\n";
open $filename; #edit?
read go;

rsync $filename $host:/var/www/screenshots/subdir/;
echo "http://$domain/$filename" | pbcopy;

mv $filename ~/Documents/work/screenshots/;
osascript -e 'display notification "The image has been uploaded to your server." with title "Image Uploaded"';

That will take an interactive screenshot, open it in Preview so that you can edit and save it, then continue and upload it to your webhost when you press any key in the terminal. I have my terminal (iTerm2) set to hide with a keyboard combo (ctrl+space) so that I can tell it to get out of the way if I’m taking a screenshot of something else. I assigned the script to a bash alias, so all I have to to do is open a terminal and type my alias. It also copies the url to the screenshot to your clipboard using pbcopy so that you can just paste it when you want to share it.

Leave a comment

Your email address will not be published. Required fields are marked *