Writing a screenshot sharing tool using bash + S3

bash uploader

In a previous life I had a paid corporate subscription to CloudApp, and if you’re looking for a polished and easy to use screen grab / sharing tool you could do a lot worse.

However, being too cheap to pay for it from my own pocket (and wanting more control over my stored images) I wanted to try and create similar functionality in a simple way, that would work well with my Linux desktop.

Firstly I needed to find a screenshot tool that would allow me to take the snapped image and upload it in some way. Luckily there a few available: shutter, flameshot, ksnip, and many more. I tried out a few and stuck with ksnip, it has good post-snap editing functionality, the ability to upload via a custom script, and seems reasonably well maintained. While it is available on various app stores (flatpak, snap) I found that the wall garden way in which these packages run gave me problems when calling out to my script with the images. I recommend installing using a package.

Next I wrote the script, which you can find on GitHub here if you’re interested. The idea is simple, we upload the file to an S3 bucket, give it a random filename that should hopefully be unique, and print it to stdout which can be then read by the screenshot tool. I generated a random UUID using the output from /dev/random then use s3cmd to upload the file, writing any output from that to /dev/null so that it doesn’t confuse the screenshot app.

One of my favourite parts of CloudApp is that with a paid subscription you can set your own custom domain for sharing. Luckily this was simple to do here as well, I simply pointed my domain to the S3 bucket using a CNAME record, and used that when printing out the final URL.

Happily this script can be used just fine from the command line, uploading any file that you pass as a parameter, but the final piece of the puzzle was integrating this into the ksnip. Find the script uploader settings and point it to your script.

ksnip

And that’s it! There’s a few niggles, I’m not fully sold on ksnip, it seems to disappear from time to time, and you still need to press a button to upload the image, but these few lines of code allow me to easily share screenshots with my custom domain!

https://github.com/rossdeane/bash-upload