2020-07-01 13:42:14 +03:00
|
|
|
#!/bin/sh
|
2020-11-11 02:49:54 +02:00
|
|
|
#
|
|
|
|
# Siina's bootleg screenshot capturer for use with global keybinds
|
|
|
|
#
|
|
|
|
# Requires:
|
2020-11-21 10:17:18 +02:00
|
|
|
# - maim: takes the screenshot
|
2022-01-08 18:52:51 +02:00
|
|
|
# - imagemagick: for custom resolution sizes
|
2020-11-11 02:49:54 +02:00
|
|
|
# - mpv: plays audio file upon completion
|
|
|
|
# - boop.sh: uploads screenshot to boop.icu
|
2022-03-13 08:27:19 +02:00
|
|
|
# - Checks for SCREENSHOT_DIR environment variable
|
2020-11-11 02:49:54 +02:00
|
|
|
#
|
|
|
|
# Example global keybinds:
|
|
|
|
#
|
2022-03-13 08:27:19 +02:00
|
|
|
# TYPE CMD KEYBIND
|
2020-11-11 02:49:54 +02:00
|
|
|
#
|
2022-03-13 08:27:19 +02:00
|
|
|
# Fullscreen scrot.sh Print
|
|
|
|
# Main monitor scrot.sh --main Meta+Ctrl+Print
|
|
|
|
# Active window/Select scrot.sh --select Meta+Print
|
2020-11-11 02:49:54 +02:00
|
|
|
#
|
|
|
|
# TODO: Figure out how to capture a specific monitor, not just main
|
2022-03-13 08:27:19 +02:00
|
|
|
# TODO: Remove hardcoded shutter sound path
|
2020-07-01 13:42:14 +03:00
|
|
|
|
2022-03-13 08:27:19 +02:00
|
|
|
source ~/.profile # Workaround to avoid using /bin/bash
|
2022-03-13 03:08:15 +02:00
|
|
|
|
2022-03-13 08:27:19 +02:00
|
|
|
# Edit these to fit setup
|
2020-12-20 20:30:34 +02:00
|
|
|
sound="$HOME/Projects/local-bin/sounds/shutter.ogg"
|
2020-11-11 02:49:54 +02:00
|
|
|
filename="$(date +'%Y%m%d_%H%M%S').png"
|
2022-03-13 08:27:19 +02:00
|
|
|
main_res="1920x1080+0+510"
|
|
|
|
secondary_res="1080x1920+1920+0"
|
2022-03-13 03:08:15 +02:00
|
|
|
|
2022-03-13 08:27:19 +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
|
2020-11-11 02:49:54 +02:00
|
|
|
|
2022-03-13 08:27:19 +02:00
|
|
|
# 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
|
|
|
|
2022-03-13 08:27:19 +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
|
2022-01-08 18:52:51 +02:00
|
|
|
maim -B $args $filename > /dev/null 2>&1
|
|
|
|
|
2022-03-13 08:27:19 +02:00
|
|
|
# cleanup for main monitor
|
|
|
|
if [[ ${1} == "--main" ]]; then
|
2022-03-13 03:08:15 +02:00
|
|
|
magick convert $filename -trim +repage $SCREENSHOT_DIR/$filename
|
2022-01-08 18:52:51 +02:00
|
|
|
fi
|
2020-11-21 10:17:18 +02:00
|
|
|
|
2022-03-13 08:27:19 +02:00
|
|
|
# Play sound if mpv is available
|
|
|
|
if [[ -n "$(which mpv)" ]]; then
|
|
|
|
mpv $sound
|
|
|
|
fi
|
2020-07-01 13:42:14 +03:00
|
|
|
|
2022-03-13 08:27:19 +02:00
|
|
|
# Upload to boop if boop.sh is available
|
|
|
|
if [[ -n "$(which boop.sh)" ]]; then
|
|
|
|
boop.sh "$SCREENSHOT_DIR/$filename"
|
|
|
|
fi
|