Skip to content

Instantly share code, notes, and snippets.

@Matt1360
Last active December 21, 2015 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Matt1360/6341566 to your computer and use it in GitHub Desktop.
Save Matt1360/6341566 to your computer and use it in GitHub Desktop.
Screenshot script I use for things like screenshots, and screenshot accessories that can be used with multiple X screens.For good things(tm), I recommend binding keyboard shortcuts to the script.I should also note, you want public keys set up to upload it. Yarr.
#!/bin/bash
# Ensure some arg
if [ -z "$1" ]
then
echo "No arguments!"
exit -1
fi
# Full screenshot - both X screens
if [ $1 = "full" ]
then
# Basically, for each display, take a screenshot, throw 'er in /tmp
import -window root -display :1.0 -screen /tmp/ss-0.png;
import -window root -display :1.1 -screen /tmp/ss-1.png;
# Now stitch 'em together
convert +append /tmp/ss-0.png /tmp/ss-1.png /tmp/screenshot.png;
# Clean 'em up
rm /tmp/ss-{0,1}.png;
# Single window
# Disclaimer: I've only tested this on my desktop and laptop
# Guarenteed happiness for all is not so guarenteed.
elif [ $1 = "win" ]
then
# Get some data from X
activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)");
activeWinId=${activeWinLine:40};
# Take the screenshot
import -window "$activeWinId" /tmp/screenshot.png;
# Click and drag (pretty sweet, yeah)
elif [ $1 = "scroll" ]
then
# This is neat, it handles crap for me
import +repage /tmp/screenshot.png;
# Grab current X screen
elif [ $1 = "single" ]
then
# Simple, just take the root window of the current X screen
import -window root -screen /tmp/screenshot.png;
fi
# Get the timestamp
TIMESTAMP=`date +%s`
# Filepath
FILEPATH="/var/www/site.com/htdocs/screenshots/"
scp /tmp/screenshot.png site.com:$FILEPATH$TIMESTAMP.png
# Put it into our clipboard (middle click)
echo https://site.com/screenshots/$TIMESTAMP.png | xclip -selection clipboard
# Use lib-notify to tell us when it's ready, which is neat
notify-send 'Screenshot!' "Timestamp: ${TIMESTAMP}"
# EXIT ZEROS
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment