slurp
slurp copied to clipboard
Add a debug msg to distinguish cancellation by ESC and click
As mentioned in https://github.com/emersion/slurp/pull/126, I bind a script to 'Print' key and intend to use 'ESC' to cancel and 'click' to take a whole screenshot.
Currently, both ESC and click print out same msg 'selection cancelled', and I need a different msg to distinguish cancellation by ESC from click.
The previous try in https://github.com/emersion/slurp/pull/126 is stupid. What I need is just a different msg, one more fprintf
is enough for that.
The script I use:
#!/usr/bin/bash
IMG_VIEWER=pqiv
FILENAME=screenshot-$(LANG=C LC_ALL=C date "+%Y-%m-%d-%H-%M-%S").png
SELECT=$(LANG=en_US slurp 2>&1)
if [ "$SELECT""x" == "ESC pressed selection cancelled""x" ]; then
true
elif [ "$SELECT""x" == "selection cancelled""x" ]; then
grim "$HOME"/"$FILENAME" && $IMG_VIEWER "$HOME"/"$FILENAME"
else
grim -g "$SELECT" "$HOME"/"$FILENAME" && $IMG_VIEWER "$HOME"/"$FILENAME"
fi
Error messages should not be relied upon. They might change, be localized, etc. They are for human consumption only.
Error messages should not be relied upon. They might change, be localized, etc. They are for human consumption only.
I am not sure which is your prefer way, and took a look at hacksaw, 'click' print 'global cursor pos 0x0' and 'ESC' report a cancellation msg, it can be used to:
- distinguish 'click' from 'ESC'.
- take a screenshot of window at global cursor pos if screenshot utility support it.