Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
Last active April 14, 2023 19:52
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sp3c73r2038/3741659 to your computer and use it in GitHub Desktop.
Save sp3c73r2038/3741659 to your computer and use it in GitHub Desktop.
a script using ImageMagick to take screenshots
#!/bin/bash
DIR="${HOME}/images/screenshots"
DATE="$(date +%Y%m%d-%H%M%S)"
NAME="${DIR}/screenshot-${DATE}.png"
LOG="${DIR}/screenshots.log"
# Check if the dir to store the screenshots exists, else create it:
if [ ! -d "${DIR}" ]; then mkdir -p "${DIR}"; fi
# Screenshot a selected window
if [ "$1" = "win" ]; then import -format png "${NAME}"; fi
# Screenshot the entire screen
if [ "$1" = "scr" ]; then import -format png -window root "${NAME}"; fi
# Screenshot a selected area
if [ "$1" = "area" ]; then import -format png "${NAME}"; fi
if [[ $# = 0 ]]; then
# Display a warning if no area defined
echo "No screenshot area has been specified. Screenshot not taken."
echo "${DATE}: No screenshot area has been defined. Screenshot not taken." >> "${LOG}"
else
# Save the screenshot in the directory and edit the log
echo "${NAME}" >> "${LOG}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment