forked from jbenet/ipfs-screencap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portable-screencap
executable file
·65 lines (56 loc) · 1.08 KB
/
portable-screencap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
USAGE="usage: $0 - take a screenshot and output to stdout, portably"
usage() {
echo "$USAGE"
exit 0
}
die() {
echo >&2 "error: $@"
exit 1
}
# get user options
while [ $# -gt 0 ]; do
# get options
arg="$1"
shift
case "$arg" in
-h|--help) usage ;;
--*)
die "unrecognised option: '$arg'\n$USAGE" ;;
*)
die "$0 accepts no arguments\n$USAGE" ;;
esac
done
darwin_screencap() {
screencapture -i "$1"
}
linux_screencap() {
if type import >/dev/null
then
import "$1"
elif type shutter >/dev/null
then
shutter -e -o "$1"
elif type scrot >/dev/null
then
scrot "$1"
else
die "cannot find a supported screen capture tool
please install a supported one:
imagemagick
shutter
scrot"
fi
}
all_screencap() {
case $(uname) in
Darwin) darwin_screencap "$1" ;;
Linux) linux_screencap "$1" ;;
*) die "screencap not implemented for $(uname)" ;;
esac
}
date=$(date +"%Y-%m-%dT%H:%M:%SZ")
fpath=$(mktemp "/tmp/screencap.$date.XXXXXX.png")
all_screencap "$fpath" || die "capture failed"
cat "$fpath"
rm "$fpath" || true