1

I used to use "Gadwin print screen" on Windows where I could just press a shortcut and a predefined screen area would get saved to a folder (no questions asked), which is very helpful while doing lengthy online courses .

I have switched to Ubuntu and I need an alternative. I have installed Shutter and managed to create a shortcut that can trigger the "selection" tool and auto save the picture, but the problem is I need to re-position the predefined selection area (which is positioned on lower right of screen by default), and shutter doesn't remember the previous position, which is time consuming in my usage scenario where hundreds of screen shots are taken.

b_laoshi
  • 4,660
  • 4
  • 25
  • 46
dipu
  • 69
  • Using scrot: see https://askubuntu.com/a/585698/72216. Works equally on any Ubuntu version. You'still need to install scrot though. – Jacob Vlijm Jun 04 '17 at 18:21
  • I need to capture a predefined area and save it automatically with press of a key. The whole procedure need to be done on a single key press. Please understand my question properly, i don't want to open command line or adjust capture area each time i press screenshot key, because its too difficult while taking hundreds of screenshots at a time. @jacob Vlijm – dipu Jun 04 '17 at 18:43
  • 2
    Uuuuhm.... here's an idea: add the command to a shortcut key. – Jacob Vlijm Jun 04 '17 at 18:47

1 Answers1

3

Bind a script that implements scrot and imagemagick to a keyboard shortcut

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" imageName="$(date +%Y-%m-%d.%H:%M:%S.%N).jpg" # save image names as timestamp left=10 # begin crop this number of pixels from the left of the image top=10 # begin crop this number of pixels from the top of the image width=100 # crop this many pixels wide height=100 # crop this many pixels tall

#Do not make any more changes from here down unless you know what you're doing imagePath="$screenshotDir/$imageName"

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

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).

b_laoshi
  • 4,660
  • 4
  • 25
  • 46
  • Thanks for helping me out. I created a screenshot.sh file from the script you provided and double clicked it, but it did't workout. Here is the error message "The file you opened has some invalid characters. If you continue editing this file you could corrupt this document. You can also choose another character encoding and try again." I added the shortcut too and did't get any results. @b_laoshi – dipu Jun 11 '17 at 15:09
  • That sounds like a problem with the editor you used to create the file or to make changes. Might I recommend using nano? Copy the script from the page above, in a terminal, type nano /path/to/screenshot.sh then once that opens, delete any text already there and press Ctrl+Shift+V to paste. Save that and make it read only. To save, you'll want to press Ctrl+X, Y, Enter. – b_laoshi Jun 12 '17 at 01:35
  • One thing to check for sure is that the double quote character looks like this " and not this or this . These are three distinctly different characters, and the last two will not parse correctly. – b_laoshi Jun 12 '17 at 01:40
  • Sorry for the late reply. I tried what you said and now when i double click on screenshot.sh it opens in a text editor and displays the script that i entered. I can't make it read only file. How to make it an executable program that can take screen shots ?. – dipu Jun 15 '17 at 15:33
  • There are 2 things to check. 1) the very first line of the script reads #!/bin/bash, and 2) you ran the chmod +x ... line to make the script executable. If those two things are true, when you double-click the file, you should be shown a prompt asking if you want to a) Run in Terminal, b) Display, c) Cancel, or d) Run. If you don't see this prompt, you haven't made the script executable (this prompt is only presented if the file is executable and you are double-clicking to run). You could also run the file from terminal with bash /path/to/screenshot.sh. Executable or not, this will run. – b_laoshi Jun 16 '17 at 01:02