Skip to content

Instantly share code, notes, and snippets.

@Tomin1
Last active September 21, 2018 19:37
Show Gist options
  • Select an option

  • Save Tomin1/fc772002b9eea66f6ae4 to your computer and use it in GitHub Desktop.

Select an option

Save Tomin1/fc772002b9eea66f6ae4 to your computer and use it in GitHub Desktop.
An easy way to take a screenshot and share it
#!/bin/sh
# This script is made by Tomi Leppänen aka Tomin (http://tomin.site/)
# You are free to use, copy, redistribute and modify this script
# as long as you accept that ***I won't take any responsibility
# for this code and it comes without any warranty***.
# This script takes a screenshot from the part of screen that you can
# select by mouse and then it saves the screenshot to your Dropbox
# folder (location set by DIRECTORY variable) and then pastes a shared
# link to clipboard.
# It is recommended to add this as a hotkey to your DE/WM or compositor.
# It works on Wayland sessions as well, if you change the screenshot tool
# to fit your desktop and use XWayland for xclip. If you know any command
# line program that can manipulate clipboard on Wayland without XWayland,
# please tell me.
# The name of this script comes from command line tool called scrot. If the
# word scrot was turned into a verb by Finnish language rules, it would be
# scrotata.
# Configuration:
# Date format
DATE=$(date +%Y-%m-%d-%H-%M-%S)
# Directory to save images, change to whatever you want
DIRECTORY="$HOME/Dropbox/Photos/Scrot"
# Clipboard to use, values: 'clipboard' for keyboard,
# and 'primary' for mouse-middle-click
# or 'both' for both of them
CLIPBOARD='primary'
# Screenshot tool, if you know other useful tools, feel free to email me
COMMAND='scrot -s'
#COMMAND='gnome-screenshot -a -f'
# Dropbox command, this may be different on some distributions
DROPBOX='dropbox'
#DROPBOX='dropbox-cli'
# Check dependencies
if [ -z $(which ${COMMAND%% *}) 2> /dev/null ]
then echo "Screenshot tool is requred! Install or configure it"
exit
fi
if [ -z $(which xclip) 2> /dev/null ]
then echo "Xclip is required! Install xclip"
exit
fi
if [ -z $(which $DROPBOX) 2> /dev/null ]
then echo "Dropbox is required! Install dropbox command line tool"
exit
fi
# The code
$COMMAND "$DIRECTORY/$DATE.png" || exit
PUBURL=$($DROPBOX sharelink "$DIRECTORY/$DATE.png" |tr -d "\n")
if [ $CLIPBOARD == "both" ]; then
echo -n "$PUBURL" |xclip -selection clipboard
echo -n "$PUBURL" |xclip -selection primary
else
echo -n "$PUBURL" |xclip -selection $CLIPBOARD
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment