Skip to content

Instantly share code, notes, and snippets.

@chadkouse
Last active November 6, 2023 22:24
Show Gist options
  • Save chadkouse/17d8fee288d67b6cf6f962bba4bb849f to your computer and use it in GitHub Desktop.
Save chadkouse/17d8fee288d67b6cf6f962bba4bb849f to your computer and use it in GitHub Desktop.
Automatically upload screenshots and screen recordings to s3, like jumpshare for linux

Make sure you have a working and configured s3cmd and you have notify-send installed

Update upload_screenshot to point to your s3 bucket and path

you may need to update DISPLAY and DBUS_SESSION_BUS_ADDRESS (from a working terminal in your X session you can find these by doing echo $DISPLAY && echo $DBUS_SESSION_BUS_ADDRESS )

make sure upload_screenshot is in your (and probably root's) PATH (I put mine in /usr/local/bin) -- also make sure it's executable chmod a+x upload_screenshot

Set up the directory to watch in your incrontab (in my example /home/chadkouse/screenshots ) Any file you put into this directory will get uploaded to s3 and it's url copied to the clipboard.

I use https://github.com/lupoDharkael/flameshot for screenshots and https://github.com/phw/peek for screen recording

the .desktop entry allows content to be sent directly to s3 without first saving in your output directory (flameshot has an option for this, peek does not)

/home/myusername/screenshots IN_CREATE upload_screenshot $@/$#
[Desktop Entry]
Name=Upload Screenshot
Exec=upload_screenshot %U
Icon=image
Type=Application
Terminal=true
Categories=Graphics;
MimeType=image/png;
#!/bin/bash
export DISPLAY=:1
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
bucketname="mybucketname"
path="/s/"
function u2b {
v=$(date +%s)
BASE62=($(echo {0..9} {a..z} {A..Z}))
for i in $(bc <<< "obase=62; $v"); do echo -n ${BASE62[$(( 10#$i ))]}
done
}
r=$(u2b)
filename=$(basename -- "$1")
ext="${filename##*.}"
url=`s3cmd -d -v put --acl-public "$1" "s3://$bucketname$path$r.$ext" | grep "Public URL" | cut -d ':' -f 2-`
surl="${url/http:/https:}"
echo $surl | xsel -b
notify-send --hint=int:transient:1 "Screenshot URL Copied to clipboard"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment