Skip to content

Instantly share code, notes, and snippets.

@gdhaworth
Created September 28, 2013 01:56
Show Gist options
  • Save gdhaworth/6737571 to your computer and use it in GitHub Desktop.
Save gdhaworth/6737571 to your computer and use it in GitHub Desktop.
Automatically open a screenshot for viewing after it is taken and delete after it is closed. Requires inotify-tools. This is written and tested on Gnome with Shotwell, probably can be adapted to other systems by changing the screenshot filename pattern (line 16) and the photo viewing application (line 18).
#!/bin/bash
if [[ -z "$1" ]]; then
_monitor_dir="$HOME/Pictures"
else
_monitor_dir="$1"
fi
if [[ ! -d "${_monitor_dir}" ]]; then
echo "Can't find directory '${_monitor_dir}', does it exist?"
exit 1
fi
inotifywait -m -e create --format '%f' "${_monitor_dir}" \
| while read file; do
if [[ "$file" = Screenshot\ from\ * ]]; then
echo "File created: '$file'"
shotwell "${_monitor_dir}/$file"
rm -f "${_monitor_dir}/$file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment