Skip to content

Instantly share code, notes, and snippets.

@ihabunek
Last active November 9, 2018 14:00
Show Gist options
  • Save ihabunek/7c0bebf96074bf447829b39e13dab05c to your computer and use it in GitHub Desktop.
Save ihabunek/7c0bebf96074bf447829b39e13dab05c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Find an unused file name to capture to
DIR=~/Pictures/Screenshots/
N=1
while [ -f "$DIR`printf %05d $N`.png" ]; do
N=$((N+1))
done
FILENAME=$DIR`printf %05d $N`.png
# Take screenshot, if successful copy to clipboard and show notification
if maim -s > $FILENAME; then
xclip -selection clip -target image/png < $FILENAME
notify-send "Screenshot saved" $FILENAME
fi
@afarazit
Copy link

afarazit commented Nov 9, 2018

line 4 should be "DIR=~/Pictures/Screenshots/" so that everyone can take your script and use it without the need to modify the home path

@ihabunek
Copy link
Author

ihabunek commented Nov 9, 2018

@afarazit Actually that does not work since it takes a literal ~ instead of expanding it. However if you remove the quotes then it works. I'll change the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment