commit d7917c209b5581fca6c687e7fba0f19a01c23d67 Author: admin Date: Thu Mar 6 07:26:45 2025 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0dbe287 --- /dev/null +++ b/README.md @@ -0,0 +1,103 @@ +# i3 Screenshot Tool + +A collection of scripts for taking screenshots in i3 window manager on Linux (CachyOS), with a focus on the "freeze and select" functionality. + +## Features + +- **Freeze and Select**: Freeze the screen and then select an area to capture +- **Simple Selection**: Direct area selection without freezing (faster but without the freeze effect) +- **Clipboard Integration**: Automatically copies screenshots to clipboard +- **Notifications**: Desktop notifications when screenshots are taken +- **Timestamp Naming**: Automatically names files with timestamps + +## Requirements + +These scripts depend on various Linux utilities. Install them using your package manager: + +```bash +# For Arch-based distros (including CachyOS) +sudo pacman -S maim slop i3lock feh scrot imagemagick xclip xdotool + +# For Debian/Ubuntu-based distros +sudo apt install maim slop i3lock feh scrot imagemagick xclip xdotool +``` + +## Installation + +1. Clone this repository or download the scripts: + +```bash +git clone https://github.com/yourusername/i3-screenshot.git +cd i3-screenshot +``` + +2. Make the scripts executable: + +```bash +chmod +x i3-screenshot.sh i3-screenshot-alt.sh i3-screenshot-simple.sh +``` + +3. Move the scripts to a directory in your PATH (optional): + +```bash +sudo cp i3-screenshot*.sh /usr/local/bin/ +``` + +## Configuration + +Add the following lines to your i3 config file (typically `~/.config/i3/config`): + +``` +# Screenshot with freeze and area selection (main script) +bindsym Print exec --no-startup-id /path/to/i3-screenshot.sh + +# Alternative screenshot with freeze and area selection +bindsym Shift+Print exec --no-startup-id /path/to/i3-screenshot-alt.sh + +# Simple screenshot with area selection (no freeze) +bindsym Ctrl+Print exec --no-startup-id /path/to/i3-screenshot-simple.sh +``` + +Replace `/path/to/` with the actual path to the scripts. + +## Usage + +- Press `Print Screen` to use the main freeze-and-select screenshot tool +- Press `Shift+Print Screen` to use the alternative freeze-and-select tool +- Press `Ctrl+Print Screen` to use the simple area selection tool without freezing + +After pressing the key combination: +1. For the freeze scripts: The screen will freeze, and you can select an area with your mouse +2. For the simple script: The screen will dim, and you can select an area with your mouse +3. The screenshot will be saved to `~/Pictures/Screenshots/` with a timestamp +4. The screenshot will also be copied to your clipboard +5. A notification will appear confirming the screenshot was taken + +## How It Works + +### Main Script (`i3-screenshot.sh`) +Uses `maim` to take a full screenshot, displays it with `i3lock` to freeze the screen, then uses `slop` for area selection and `maim` again to capture just that area. + +### Alternative Script (`i3-screenshot-alt.sh`) +Uses `scrot` for the initial screenshot, `feh` to display it fullscreen, `slop` for selection, and `imagemagick` to crop the image. + +### Simple Script (`i3-screenshot-simple.sh`) +Uses just `maim` with the `-s` flag for direct area selection without freezing the screen first. + +## Customization + +You can modify the scripts to change: +- The save location by editing the `SAVE_DIR` variable +- The notification messages +- The file naming convention + +## Troubleshooting + +- If the scripts don't work, make sure all dependencies are installed +- Check that the scripts have executable permissions +- Verify your i3 config has the correct paths to the scripts +- If using the i3lock method, ensure your system supports i3lock with image display + +## License + +This project is licensed under the MIT License - see the LICENSE file for details. \ No newline at end of file diff --git a/i3-config-example.txt b/i3-config-example.txt new file mode 100644 index 0000000..113cbe6 --- /dev/null +++ b/i3-config-example.txt @@ -0,0 +1,18 @@ +# i3 config file example for screenshot tool bindings +# Add these lines to your i3 config file (typically ~/.config/i3/config) + +# Screenshot with freeze and area selection (main script) +bindsym Print exec --no-startup-id /path/to/i3-screenshot.sh + +# Alternative screenshot with freeze and area selection +bindsym Shift+Print exec --no-startup-id /path/to/i3-screenshot-alt.sh + +# Simple screenshot with area selection (no freeze) +bindsym Ctrl+Print exec --no-startup-id /path/to/i3-screenshot-simple.sh + +# You can also add more specific bindings if needed +# For example, to capture the active window: +bindsym $mod+Print exec --no-startup-id maim -i $(xdotool getactivewindow) | xclip -selection clipboard -t image/png + +# Or to capture the entire screen: +bindsym $mod+Shift+Print exec --no-startup-id maim | xclip -selection clipboard -t image/png \ No newline at end of file diff --git a/i3-screenshot-alt.sh b/i3-screenshot-alt.sh new file mode 100755 index 0000000..86adfa7 --- /dev/null +++ b/i3-screenshot-alt.sh @@ -0,0 +1,58 @@ +#!/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" \ No newline at end of file diff --git a/i3-screenshot-import.sh b/i3-screenshot-import.sh new file mode 100644 index 0000000..930a4c0 --- /dev/null +++ b/i3-screenshot-import.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# i3-screenshot-import.sh - Alternative tool using ImageMagick's import +# This script uses a different approach that might work better on some systems + +# 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 screenshot of selected area using import +notify "Select an area to capture" +import "$SCREENSHOT_PATH" + +# Check if screenshot was taken successfully +if [ $? -ne 0 ]; then + notify "Screenshot canceled" + exit 1 +fi + +# 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" \ No newline at end of file diff --git a/i3-screenshot-simple.sh b/i3-screenshot-simple.sh new file mode 100755 index 0000000..f72a8e5 --- /dev/null +++ b/i3-screenshot-simple.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# i3-screenshot-simple.sh - Simple tool for taking selective screenshots in i3 +# This script uses maim and slop for direct area selection without freezing + +# 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 +} + +# Use maim with slop for area selection +maim -s "$SCREENSHOT_PATH" + +# Check if screenshot was taken successfully +if [ $? -ne 0 ]; then + notify "Screenshot canceled" + exit 1 +fi + +# 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" \ No newline at end of file diff --git a/i3-screenshot.sh b/i3-screenshot.sh new file mode 100755 index 0000000..35310a4 --- /dev/null +++ b/i3-screenshot.sh @@ -0,0 +1,58 @@ +#!/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" \ No newline at end of file