From eec0a701590e12e0aeded6cd9b446af30f56a886 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 14 Jul 2024 02:16:56 +0100 Subject: [PATCH] Handle cancelled screenshot in screenshot.sh --- screenshot.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/screenshot.sh b/screenshot.sh index 4e76d01..61a19bd 100755 --- a/screenshot.sh +++ b/screenshot.sh @@ -1,7 +1,12 @@ #!/bin/sh # Screenshot script with selection using maim and notification. filepath="$HOME/media/images/screenshots/$(date +%Y-%m-%d\ %H:%M:%S).png" -maim --select --hidecursor | tee "$filepath" | xclip -selection clipboard -target image/png +maim --select --hidecursor | tee "$filepath" | xclip -selection clipboard -target image/png -# send notification with a thumbnail of the screenshot taken, the name of the script, and the filepath -notify-send --icon "$filepath" "$(basename "$0")" "Screenshot saved to: $filepath" +# if maim is cancelled, tee will create an empty file, so checking if the file is empty +if [ -s "$filepath" ]; then + # send notification with a thumbnail of the screenshot taken, the name of the script, and the filepath + notify-send --icon "$filepath" "$(basename "$0")" "Screenshot saved to: $filepath" +else + rm "$filepath" +fi