Skip to content

Instantly share code, notes, and snippets.

@rokoucha
Created January 24, 2017 03:58
Show Gist options
  • Save rokoucha/dabcff84417f5825479e07941276be0b to your computer and use it in GitHub Desktop.
Save rokoucha/dabcff84417f5825479e07941276be0b to your computer and use it in GitHub Desktop.
Snappy - screenshot tool
#!/bin/bash
#Snappy
save_folder=$HOME/Pictures/Screenshot
save_file=Screenshot-$(date +"%Y-%m-%d-%I-%M-%S").png
save=0
save_path=$(mktemp).png
usage_exit() {
echo "Usage: $0 [OPTIONS]" 1>&2
echo "If you don't use -a/-s,Snappy will not save screenshot in the file." 1>&2
echo "" 1>&2
echo "-h display this help and exit" 1>&2
echo "-a save screenshot in ~/Pictures/Screenshots" 1>&2
echo "-d wait NUM seconds before taking a shot" 1>&2
echo "-r interactively choose a window or rectangle with the mouse" 1>&2
echo "-s save screenshot in FILE" 1>&2
echo "-w use the currently focused window" 1>&2
exit 1
}
while getopts adrswh OPT
do
case $OPT in
a) save=1
save_path="$save_folder/$save_file"
;;
d) delay=$(zenity --scale --text="delay time" --value=5 --min-value=0 --max-value=10 --step=1) && scrot_option="$scrot_option -d $delay"
;;
h) usage_exit
;;
r) scrot_option="$scrot_option -s"
;;
s) save_path=$(zenity --file-selection --filename=$save_file --save) && save=1
;;
w) scrot_option="$scrot_option -u"
;;
esac
done
shift $((OPTIND - 1))
scrot $scrot_option $save_path
canberra-gtk-play --file=/usr/share/sounds/freedesktop/stereo/screen-capture.oga
xclip -selection clipboard -t image/png -i $save_path
if [ $save = 0 ]; then
rm $save_path
notify-send "Screenshot is copied to clipboard" --icon=dialog-information
else
notify-send "Screenshot is copied to clipboard and save in $save_path" --icon=dialog-information
fi
unset save
unset save_file
unset save_folder
unset scrot_option
unset delay
unset save_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment