Bind a bash script that implements scrot and imagemagick to a keyboard shortcut
This does nearly the same thing as Jacob Vlijm's answer but with bash. It names files using a timestamp to avoid overwriting existing files. It also allows you to define default cropping parameters in the script so you're not required to call it with any parameters.
Call the script below as follows (assuming you're in the directory where the script is stored, otherwise the full path to the script is required):
- With parameters:
./screenshot.sh $left_px $top_px $width_px $height_px
OR
- Without parameters:
./screenshot.sh
in which case, the default parameters specified in the script are used.
1) Install the necessary applications
From the command line, run:
sudo apt install scrot imagemagick
2) Create the script
Open your text editor of choice and create a new plaintext file with the following contents. Be sure the modify the variables at the top to specify where you want the images saved and what portion of the screen you want to crop out. See this trick for getting mouse coordinates which can be used to find left
and top
and to calculate width
and height
.
#!/bin/bash
# Change these values to match your preferences
imageQuality=100 # scrot default is 75
screenshotDir="/tmp" # directory in which to save screenshots
imageName="$(date +%Y-%m-%d.%H:%M:%S.%N).jpg" # save image names as timestamp
default_left=10 # begin crop this number of pixels from the left of the image
default_top=10 # begin crop this number of pixels from the top of the image
default_width=100 # crop this many pixels wide
default_height=100 # crop this many pixels tall
#Do not make any more changes from here down unless you know what you're doing
l=$1; t=$2; w=$3; h=$4
left=${l:=$default_left}
top=${t:=$default_top}
width=${w:=$default_width}
height=${h:=$default_height}
imagePath="$screenshotDir/$imageName"
[ ! -d "$screenshotDir" ] && mkdir -p "$screenshotDir"
scrot -q $imageQuality "$imagePath"
convert "$imagePath" -crop ${width}x${height}+${left}+${top} "$imagePath"
Save this script wherever you like and make it executable. Assuming you named your script screenshot.sh
, you would do this at the command line like so:
chmod +x /path/to/your/script/screenshot.sh
3) Bind this script to a keyboard shortcut (optional)
Follow the directions found here to create a custom keyboard shortcut. When you get to the point where you're supposed to enter the command, put the complete path to your screenshot.sh
file (including the filename).
--exit_after_capture
option ofshutter
? Also, many GUI programs generate such warnings when run from the command line. Nothing to really worry about.