Refactored scrot.sh and added secondary display capture

This commit is contained in:
Siina Mashek 2022-03-13 08:27:19 +02:00
parent 4b6d90efc6
commit 4bd4743f95
2 changed files with 66 additions and 31 deletions

View File

@ -7,54 +7,63 @@
# - imagemagick: for custom resolution sizes # - imagemagick: for custom resolution sizes
# - mpv: plays audio file upon completion # - mpv: plays audio file upon completion
# - boop.sh: uploads screenshot to boop.icu # - boop.sh: uploads screenshot to boop.icu
# - Checks for SCREENSHOT_DIR environment variable
# #
# Example global keybinds: # Example global keybinds:
# #
# TYPE CMD KEYBIND # TYPE CMD KEYBIND
# #
# Fullscreen scrot.sh Print # Fullscreen scrot.sh Print
# Main monitor scrot.sh -m Meta+Ctrl+Print # Main monitor scrot.sh --main Meta+Ctrl+Print
# Active window/Selct scrot.sh -s Meta+Print # Active window/Select scrot.sh --select Meta+Print
# #
# TODO: Autodetect mpv and boop.sh to make them optional
# TODO: Figure out how to capture a specific monitor, not just main # TODO: Figure out how to capture a specific monitor, not just main
# TODO: Remove hardcoded shutter sound path
source ~/.profile # Workaround source ~/.profile # Workaround to avoid using /bin/bash
# Checks for SCREENSHOT_DIR environment variable # Edit these to fit setup
#screendir="$HOME/Screenshots"
sound="$HOME/Projects/local-bin/sounds/shutter.ogg" sound="$HOME/Projects/local-bin/sounds/shutter.ogg"
filename="$(date +'%Y%m%d_%H%M%S').png" filename="$(date +'%Y%m%d_%H%M%S').png"
resolution="1920x1080" main_res="1920x1080+0+510"
secondary_res="1080x1920+1920+0"
# For desktop multi-monitor
if [[ ${1} == "-d" ]]; then
resolution="1920x1590"
fi
args="-m 9 -u"
# Ensure screenshot directory is there so the script will work
if [[ ! -d $SCREENSHOT_DIR ]]; then if [[ ! -d $SCREENSHOT_DIR ]]; then
mkdir -p $SCREENSHOT_DIR mkdir -p $SCREENSHOT_DIR
fi fi
echo "Entering $SCREENSHOT_DIR"
cd $SCREENSHOT_DIR cd $SCREENSHOT_DIR
if [[ ${1} == "-m" ]]; then # Setup is 1920x1590: main = 1920x1080; secondary = 1080x1920
args="${args} -g ${resolution}+0+510" # for standard 1080p single monitor if [[ ${1} == "--main" ]]; then
else resolution=$main_res
args="${args}" elif [[ ${1} == "--secondary" ]]; then
resolution=$secondary_res
fi fi
# 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 maim -B $args $filename > /dev/null 2>&1
# cleanup for my dual-monitor setup # cleanup for main monitor
if [[ ${1} == "-d" ]]; then if [[ ${1} == "--main" ]]; then
magick convert $filename -trim +repage $SCREENSHOT_DIR/$filename magick convert $filename -trim +repage $SCREENSHOT_DIR/$filename
fi fi
# Play sound if mpv is available
if [[ -n "$(which mpv)" ]]; then
mpv $sound mpv $sound
$HOME/.local/bin/boop.sh "$SCREENSHOT_DIR/$filename" fi
# Upload to boop if boop.sh is available
if [[ -n "$(which boop.sh)" ]]; then
boop.sh "$SCREENSHOT_DIR/$filename"
fi

View File

@ -3,7 +3,7 @@ DataCount=1
[Data_1] [Data_1]
Comment=Comment Comment=Comment
DataCount=3 DataCount=4
Enabled=true Enabled=true
Name=Scrot.sh Name=Scrot.sh
SystemGroup=0 SystemGroup=0
@ -49,7 +49,7 @@ Type=SIMPLE_ACTION_DATA
ActionsCount=1 ActionsCount=1
[Data_1_2Actions0] [Data_1_2Actions0]
CommandURL=/home/siina/.local/bin/scrot.sh -m CommandURL=/home/siina/.local/bin/scrot.sh --main
Type=COMMAND_URL Type=COMMAND_URL
[Data_1_2Conditions] [Data_1_2Conditions]
@ -61,7 +61,7 @@ Comment=Simple_action
TriggersCount=1 TriggersCount=1
[Data_1_2Triggers0] [Data_1_2Triggers0]
Key= Key=Meta+Ctrl+Print
Type=SHORTCUT Type=SHORTCUT
Uuid={c339b929-b41c-4c59-928e-2fafe008b001} Uuid={c339b929-b41c-4c59-928e-2fafe008b001}
@ -75,7 +75,7 @@ Type=SIMPLE_ACTION_DATA
ActionsCount=1 ActionsCount=1
[Data_1_3Actions0] [Data_1_3Actions0]
CommandURL=/home/siina/.local/bin/scrot.sh -s CommandURL=/home/siina/.local/bin/scrot.sh --select
Type=COMMAND_URL Type=COMMAND_URL
[Data_1_3Conditions] [Data_1_3Conditions]
@ -91,6 +91,32 @@ Key=Meta+Print
Type=SHORTCUT Type=SHORTCUT
Uuid={205c92eb-bb7b-47a2-8309-b9ebf3f655e2} Uuid={205c92eb-bb7b-47a2-8309-b9ebf3f655e2}
[Data_1_4]
Comment=Comment
Enabled=true
Name=Secondary Display
Type=SIMPLE_ACTION_DATA
[Data_1_4Actions]
ActionsCount=1
[Data_1_4Actions0]
CommandURL=/home/siina/.local/bin/scrot.sh --secondary
Type=COMMAND_URL
[Data_1_4Conditions]
Comment=
ConditionsCount=0
[Data_1_4Triggers]
Comment=Simple_action
TriggersCount=1
[Data_1_4Triggers0]
Key=
Type=SHORTCUT
Uuid={3069937f-c0f2-4741-96a0-ca47d3f123f0}
[Main] [Main]
AllowMerge=false AllowMerge=false
Version=2 Version=2