2 # A quick and dirty script to take a screenshot, upload it via scp
3 # and put a link to it in the clipboard for easy pasting to i.e. IRC.
4 # It assumes a lot of things, e.g. that ssh to the target host has
5 # been set up with a working logon with private key, and that xclip and
6 # gnome-screenshot is installed.
8 # If all you have is a hammer, everything looks like a nail.
12 # * Check that we don't overwrite an existing file (theoretically possible, but unlikely)
16 RemoteHost
="wowbagger.slaskete.net"
17 RemotePath
="/var/www/eina.rjh.im/screenshots/"
18 LocalPath
="${HOME}/Pictures/Screenshots/"
19 UrlBase
="https://eina.rjh.im/g"
25 function take_screenshot
() {
26 FileID
="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 6 | head -n 1)"
27 FileName
="${FileID}.png"
28 if [ "$*" = "clipboard" ] ||
[ "$*" = "jpg" ]; then
29 xclip
-out -selection clipboard
-t image
/png
> "/tmp/${FileName}" 2>/dev
/null
30 if [ "$(file -b --mime-type "/tmp
/${FileName}")" == "image/png" ]; then
31 if [ "$*" = "jpg" ]; then
32 convert
"/tmp/${FileName}" "/tmp/${FileID}.jpg"
34 FileName
="${FileID}.jpg"
36 mv "/tmp/${FileName}" "${LocalPath}/"
39 notify-send
-a "screenshot.sh" -i dialog-warning
"Ooopsie" "Tried to post image from clipboard, but found no image there."
42 gnome-screenshot
-f "${LocalPath}/${FileName}" -p "$@"
44 if [ -f "${LocalPath}/${FileName}" ]; then
45 scp
-q "${LocalPath}/${FileName}" "${RemoteUser}@${RemoteHost}:${RemotePath}"
46 echo -n "${UrlBase}/${FileName}"|xclip
-selection p
47 echo -n "${UrlBase}/${FileName}"|xclip
-selection c
48 notify-send
-a "screenshot.sh" -i applets-screenshooter
"Screenshot uploaded" "Screenshot published to ${UrlBase}/${FileName}"
52 function show_help
() {
53 errcho
"Usage: screenshot.sh [option]"
54 errcho
"This script wraps gnome-screenshot in order to instantly upload screenshots and get back a URL for sharing to IRC or other social media"
55 errcho
"The default option is to take a screenshot of the whole screen."
56 errcho
"The following options are available:"
57 errcho
"-f, --full Take screenshot of the whole screen"
58 errcho
"-w, --window Take screenshot of the active window"
59 errcho
"-a, --area Take screenshot of an area/selection"
60 errcho
"-s, --selection Take screenshot of an area/selection"
61 errcho
"-c, --clipboard Upload image from paste buffer if present"
62 errcho
"-p, --paste Upload image from paste buffer if present"
63 errcho
"-j, --jpg, --jpeg Convert image from paste buffer to jpeg and upload"
64 errcho
"-h, --help Show this help"
72 -a|
--area|
-s|
--selection)
79 -c|
--clipboard|
-p|
--paste)
80 take_screenshot clipboard
89 errcho
"ERROR: Unknown option."