Skip to content

Instantly share code, notes, and snippets.

@Andrew-Pynch
Last active June 21, 2024 21:50
Show Gist options
  • Save Andrew-Pynch/a8d3231852eb744e32abca8ef33589af to your computer and use it in GitHub Desktop.
Save Andrew-Pynch/a8d3231852eb744e32abca8ef33589af to your computer and use it in GitHub Desktop.
#!/bin/bash
# make sure to install dependencies
# sudo apt-get install maim xclip
# if you want to make this action hotkeyable add the following lines to your
# .zshrc or .bashrc file
# alias segmented_screenshot='~/Linux-Setup-Scripts/scripts/take_segmented_screenshot.sh'
# bindkey -s '^x' 'segmented_screenshot\n' # this will bind segmented screenshot to ctrl + x
# bindsym Mod4+Shift+s exec ~/Linux-Setup-Scripts/scripts/take_segmented_screenshot.sh # binding for i3
# Take a screenshot of a selected area and save it to a temporary file
temp_file="/tmp/screenshot_$(date +%s).png"
maim -s "$temp_file"
# Check if the screenshot was taken successfully
if [ $? -eq 0 ]; then
# Copy the image to clipboard
xclip -selection clipboard -t image/png -i "$temp_file"
echo "Screenshot taken and copied to clipboard"
# Optionally, remove the temporary file
rm "$temp_file"
else
echo "Failed to take screenshot"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment