Merge pull request #502 from dylanaraps/scrot_auto

Scrot: Automatically detect tools
This commit is contained in:
Dylan Araps 2016-12-05 20:41:19 +11:00 committed by GitHub
commit e2827fefbf
2 changed files with 54 additions and 9 deletions

View file

@ -2328,7 +2328,7 @@ to_off() {
take_scrot() {
if [[ -d "$scrot_dir" ]]; then
$scrot_cmd "${scrot_dir}${scrot_name}"
scrot_program "${scrot_dir}${scrot_name}" 2>/dev/null
else
printf "%s\n" "Screenshot: $scrot_dir doesn't exist. Edit the config file or create the directory to take screenshots."
fi
@ -2372,6 +2372,47 @@ scrot_args() {
esac
}
scrot_program() {
# Detect screenshot program.
#
# We first check to see if an X server is running before
# falling back to OS specific screenshot tools.
if [[ -n "$DISPLAY" ]]; then
if [[ "$scrot_cmd" != "auto" ]] && type -p "$scrot_cmd" >/dev/null; then
scrot_program="$scrot_cmd"
elif type -p scrot >/dev/null; then
scrot_program="scrot"
elif type -p maim >/dev/null; then
scrot_program="maim"
elif type -p import >/dev/null; then
scrot_program="import -window root"
elif type -p imlib2_grab >/dev/null; then
scrot_program="imlib2_grab"
elif type -p gnome-screenshot >/dev/null; then
scrot_program="gnome-screenshot -f"
else
err "Scrot: No screen capture tool found."
return
fi
else
case "$os" in
"Mac OS X") scrot_program="screencapture -S" ;;
"Haiku") scrot_program="screenshot -s" ;;
esac
fi
# Take the scrot.
$scrot_program "$1"
err "Scrot: Screen captured using $scrot_program"
}
# TEXT FORMATTING
info() {