Blob


1 # sshot
3 sshot is a simple script to make a screenshot!
5 #!/bin/sh
7 select=
8 clip=
10 Did you know that getopts is a built-in? The first version of this
11 script used getopt, but it was ugly and required some shell features
12 which I'm not sure are POSIX. getopts is easier to handle:
14 while getopts cs name; do
15 case $name in
16 c) clip=1 ;;
17 s) select=1 ;;
18 ?) echo "Usage: $0 [-cs]" >&2; exit 1 ;;
19 esac
20 done
22 The usage is simple, it just accepts a -c flag to copy the image in the
23 clipboard and a -s flag to select a window instead of grabbing the whole
24 screen.
26 The image is saved as /tmp/YYYYMMDDHHMMSS.png
28 file=/tmp/`date +%Y%m%d%H%M%S`.png
30 if [ -n "$select" ]; then
31 maim -su > "$file"
32 else
33 maim -u > "$file"
34 fi
36 During the "select" maim aborts if a key is pressed; this however leaves
37 a zero-byte file around, something I don't really like, so remove it in
38 case
40 if [ $? -ne 0 ]; then
41 rm "$file"
42 notify-send "sshot: aborted"
43 exit 1
44 fi
46 Optionally save the image in the clipboard: (not the path, the whole
47 image!)
49 if [ -n "$clip" ]; then
50 xclip -selection clipboard -t image/png -i "$file"
51 fi
53 Then send a notification to give a feedback of the success
55 notify-send "sshot: done" "$file"