Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script which finds the newest screenshot image and adds a shadow to it
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo "Needs the filename as the first argument"
exit -1
fi
type /usr/local/bin/convert >/dev/null 2>&1 || { echo >&2 "The convert command must be available."; exit 1; }
input_filename="${1}"
output_dir="./"
if [ "${input_filename}" == "--last-screenshot" ]; then
ss_dir="/Users/claudioc/Screenshots/"
input_filename="$(ls -1rt ${ss_dir}Screenshot* | tail -1)"
if [[ "${input_filename}" =~ "_shadow" ]]; then
echo "Nothing to be done"
exit 0
fi
output_dir="${ss_dir}"
fi
# https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash#965072
filename=$(basename -- "${input_filename}")
extension="${filename##*.}"
filename="${filename%.*}"
/usr/local/bin/convert "${input_filename}" \( +clone -background black -shadow 30x8+0+0 \) +swap -background none -layers merge +repage "${output_dir}${filename}_shadow.${extension}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment