i3wm-screenshot-tool/i3-screenshot-alt.sh
2025-03-06 07:26:45 +01:00

58 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# i3-screenshot-alt.sh - Alternative tool for taking selective screenshots in i3
# This script uses scrot and imagemagick to freeze the screen and select an area
# Default save location - user's Pictures directory
SAVE_DIR="$HOME/Pictures/Screenshots"
TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S)
SCREENSHOT_PATH="$SAVE_DIR/screenshot_$TIMESTAMP.png"
# Create the save directory if it doesn't exist
mkdir -p "$SAVE_DIR"
# Function to display notification
notify() {
notify-send "Screenshot Tool" "$1" -i camera-photo
}
# Take a full screenshot first
TEMP_SCREENSHOT="/tmp/frozen_screen_$TIMESTAMP.png"
scrot "$TEMP_SCREENSHOT"
# Display the frozen screenshot in a fullscreen window
feh --fullscreen --borderless "$TEMP_SCREENSHOT" &
FEH_PID=$!
# Wait a moment for feh to display the image
sleep 0.5
# Use slop to select an area
SELECTION=$(slop -f "%x,%y,%w,%h")
if [ $? -ne 0 ]; then
# User canceled the selection
kill $FEH_PID
rm "$TEMP_SCREENSHOT"
notify "Screenshot canceled"
exit 1
fi
# Kill the feh process
kill $FEH_PID
# Extract coordinates and dimensions
IFS=',' read -r X Y W H <<< "$SELECTION"
# Crop the screenshot to the selected area
convert "$TEMP_SCREENSHOT" -crop "${W}x${H}+${X}+${Y}" "$SCREENSHOT_PATH"
# Clean up
rm "$TEMP_SCREENSHOT"
# Copy to clipboard
xclip -selection clipboard -t image/png -i "$SCREENSHOT_PATH"
# Notify user
notify "Screenshot saved to $SCREENSHOT_PATH and copied to clipboard"
echo "Screenshot saved to: $SCREENSHOT_PATH"