Configure a keyboard shortcut in Lubuntu 18.04 to take a screenshot of a screen region
October 31, 2018 6 Comments
As installed, Lubuntu 18.04 is configured so that the user can capture a screenshot of the whole screen by pressing the PrtScrn key, and a screenshot of the active window by pressing Alt+PrtScrn. However, no keyboard shortcut is configured to enable the user to capture a user-specified region of the screen.
Now, as it happens, the ‘-s
‘ option of the scrot
command allows a region of the screen to be captured and saved. The man
page for scrot
tells us:
-s, --select
Interactively select a window or rectangle with the mouse.
So here is how to configure a keyboard shortcut to do that in Lubuntu 18.04.
Open the file ~/.config/openbox/lubuntu-rc.xml
in a text editor (either nano
from the command line or LXTerminal from the GUI) and look for the following lines:
<keybind key="Print"> <action name="Execute"> <command>lxsession-default screenshot</command> </action> </keybind> <keybind key="A-Print"> <action name="Execute"> <command>lxsession-default screenshot window</command> </action> </keybind>
Append the following lines to that group of lines:
<keybind key="C-A-Print"> <action name="Execute"> <command>scrot -s</command> </action> </keybind>
The new group of lines should then look like this:
<keybind key="Print"> <action name="Execute"> <command>lxsession-default screenshot</command> </action> </keybind> <keybind key="A-Print"> <action name="Execute"> <command>lxsession-default screenshot window</command> </action> </keybind> <keybind key="C-A-Print"> <action name="Execute"> <command>scrot -s</command> </action> </keybind>
Now logout and login again.
If you now press Ctrl+Alt+PrtScrn and use your mouse to select a rectangular region of the screen, a screenshot of that region will be saved automatically to your home directory. Simple.
You just have to remember:
PrtScrn — Captures the entire screen.
Alt+PrtScrn — Captures the active window.
Ctrl+Alt+PrtScrn — Captures the area of the screen you select with the mouse.
I wonder if there is a way (on an ubuntu-like machine) to have a KB shortcut copy a user-selected rectangular section to the clipboard?
There is. Install GNOME Screenshot:
To take a screenshot of a rectangular area of the screen and save it in
~/Pictures
directory:To copy a rectangular area of the screen and save it on the clipboard so that you can paste it into other applications:
You just need to set up a keyboard shortcut in the usual way for the Desktop Environment, so that the shortcut runs that command.
See the link below for a tutorial on using GNOME Screenshot.
https://www.howtoforge.com/tutorial/taking-screenshots-in-linux-using-gnome-screenshot/
If you prefer KDE applications, Spectacle can do it from the GUI:
https://www.kde.org/images/screenshots/spectacle.png
Here’s yet another way to do it…
Install
xclip
if it is not already installed:The following command will allow you to select any region and it will save it to the clipboard and to your home directory:
You just need to set up a keyboard shortcut in the usual way for the Desktop Environment, so that the shortcut runs that command.
If you do not want the image to be saved to your home directory as well, change the above command to:
Thanks, I hadn’t used screenshotting in Linux much (if ever) and those worked great!
# I’m running a BASH Script that calls “scrot -s filename”, and uses xdotool commands to do the mouse commands to select the region I want to capture. My problem is that scrot ignores xdotool mouse commands. Is there a way to make scrot receptive of the mouse area selection from xdotool so that my Script does not require human interaction for the capture area input that scrot should use for the screen capture? “scrot -u filename” works fine, just cannot do the area selection with xdotool mouse commands. ItsYourTurn.com is the webside with the Firefox browser window being the target for the screen shot capture region.
If you mean you are trying to capture the Firefox window, you could use, for example:
scrot --delay 5 --focused
If you mean you are trying to capture a rectangle on the screen, and if you know the coordinates of the rectangle inside the Firefox window (or full screen), you can tell
scrot
to extract the rectangle after capturing the window (or full screen), using theconvert
command from ImageMagick.For example, for a captured full screen of size 1280×1024 pixels:
scrot 'test.png' --exec 'convert test.png -crop 1280x1024+400+500 test-cropped.png'
In the example above, +400+500 are the coordinates from the top left of the screen.
For example, for a captured Firefox window of size 1280×1024 pixels:
scrot --delay 5 --focused 'test.png' --exec 'sleep 5; convert test.png -crop 1280x1024+400+500 test-cropped.png'
In the example above, +400+500 are the coordinates from the top left of the captured Firefox window.