local-bin/common/scrot.sh

59 lines
1.5 KiB
Bash
Raw Normal View History

2020-07-01 13:42:14 +03:00
#!/bin/sh
#
# Siina's bootleg screenshot capturer for use with global keybinds
#
# Requires:
# - maim: takes the screenshot
# - imagemagick: for custom resolution sizes
# - boop.sh: uploads screenshot to boop.icu
# - Checks for SCREENSHOT_DIR environment variable
#
# Example global keybinds can be found in scrotsh.khotkeys
#
source ~/.profile # Workaround to avoid using /bin/bash
2022-03-13 03:08:15 +02:00
# Edit these to fit setup
2020-12-20 20:30:34 +02:00
sound="$HOME/Projects/local-bin/sounds/shutter.ogg"
filename="$(date +'%Y%m%d_%H%M%S').png"
main_res="1920x1080+0+521"
secondary_res="1080x1920+1920+0"
2022-03-13 03:08:15 +02:00
# Ensure screenshot directory is there so the script will work
2022-03-13 03:08:15 +02:00
if [[ ! -d $SCREENSHOT_DIR ]]; then
mkdir -p $SCREENSHOT_DIR
fi
cd $SCREENSHOT_DIR
# Setup is 1920x1590: main = 1920x1080; secondary = 1080x1920
if [[ ${1} == "--main" ]]; then
resolution=$main_res
elif [[ ${1} == "--secondary" ]]; then
resolution=$secondary_res
2020-07-01 13:42:14 +03:00
fi
2020-12-20 20:30:34 +02:00
# Set maim arguments based on command arguments
args="-m 9 -u"
if [[ ${1} == "--select" ]]; then
args="$args ${1}"
elif [[ ${1} == "--main" || ${1} == "--secondary" ]]; then
args="$args -g $resolution"
fi
# Take the screenshot with maim
maim -B $args $filename > /dev/null 2>&1
# cleanup for main monitor
if [[ ${1} == "--main" ]]; then
2022-03-13 03:08:15 +02:00
magick convert $filename -trim +repage $SCREENSHOT_DIR/$filename
fi
# Play sound if ffplay is available
if [[ -n "$(which ffplay)" ]]; then
ffplay $sound -nodisp -autoexit -loglevel error
fi
2020-07-01 13:42:14 +03:00
# Upload to boop if boop.sh is available
if [[ -n "$(which boop.sh)" ]]; then
boop.sh "$SCREENSHOT_DIR/$filename"
fi