magbo system

Open last image file in Gimp

I use simple script for screenshots (bind on PrtSrc key). It saves picture of current screens in home directory. Usualy I want open the picture immediately. I created simple script that opens the youngest .jpg file in current directory (named gimp-last).

#!/bin/bash
set -euo pipefail

DIR="./"
if [ $# -eq 1 ]; then
  DIR=$1
fi

if [ $# -gt 1 ]; then
  echo "Usage: $0 [DIR]"
  exit 1
fi

LAST_FILENAME=`find $DIR -maxdepth 1 -type f -name "*.jpg" -printf '%T@ %p\n' | sort -k1,1nr | head -1 | cut -d' ' -f2`
echo "Opening file '$LAST_FILENAME'"
gimp $LAST_FILENAME

If you are intersted in screenshot script here it is:

/usr/bin/import -window root "/home/petr/screenshot_$(date '+%Y-%m-%d_%H-%M-%S_%N').jpg"

Leave a Reply

Your email address will not be published. Required fields are marked *