#!/bin/sh . "lib_common.sh" . "lib_handle.sh" help() { cat << EOF ${progname}: Wrapper script to take screenshots options: -d [File] Write to File -s Select the area with the cursor -w Select the area with the cursor -h Print this message and exit NOTE: save directory is ~/media/photo/screenshot EOF exit 0 } screenshot_handle check_program default_dir="${XDG_SCREENSHOT_DIR:-${HOME}/media/photo/screenshot}" mode="fullscreen" while getopts "d:swh" option; do case "${option}" in d) input="${OPTARG}" ;; s) mode="select" ;; w) mode="focused-window" ;; h) help ;; *) invalid_use -h ;; esac done shift $((OPTIND - 1)) [ ${#} != 0 ] && invalid_use if [ -z "${input}" ]; then input="${default_dir}" mkdir -p "${default_dir}" fi outfile="${input}" [ -d "${input}" ] && outfile="${input}/$(date '+%b%d::%H%M%S').png" if [ ! -e "$(dirname "${outfile}")" ]; then mkdir -p "$(dirname "${outfile}")" || err "Failed to create directory ${outfile}" fi if [ "${mode}" = "select" ]; then run --no-exit --reload-compositor \ screenshot_handle "${mode}" "${outfile}" [ $? -eq 0 ] && echo "${outfile}" else screenshot_handle "${mode}" "${outfile}" && echo "${outfile}" fi