58 lines
1.5 KiB
Bash
Executable File
58 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# i3-screenshot.sh - A tool for taking selective screenshots in i3 window manager
|
|
# This script freezes the screen and allows selecting an area for screenshot
|
|
|
|
# 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 to use as the frozen background
|
|
TEMP_SCREENSHOT="/tmp/frozen_screen_$TIMESTAMP.png"
|
|
maim "$TEMP_SCREENSHOT"
|
|
|
|
# Display the frozen screenshot as a background using feh instead of i3lock
|
|
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 and maim to take the screenshot
|
|
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"
|
|
|
|
# Take the actual screenshot of the selected area
|
|
maim -g "${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" |