Search:  
Gentoo Wiki

TIP_Make_a_Screenshot_with_PrintScreen_Key

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

Make a screenshot

There are a few programs out there which can be used to make screenshots. ImageMagick provides a tool called import which saves any visible window on an X server and outputs it as an image file. You can capture a single window, the entire screen, or any rectangular portion of the screen.

First of all install imagemagick (please make sure both X and png USE flags are enabled):

# emerge -av imagemagick

Now type in a console:

$ import screenshot.png

then click the window you want to take a screenshot of or select a part of the screen by dragging your mouse.

If you want to make a screenshot of the whole screen issue this instead:

$ import -window root screenshot.png

Simplify things with a script

Here's a script that will make a screenshot of either a window, the entire screen or a selected area of your choice:

File: /usr/bin/screenshot
#!/bin/bash

DIR="${HOME}/screenshots"
DATE="$(date +%Y%m%d@%H%M%S)"
NAME="${DIR}/screenshot-${DATE}.png"
LOG="${DIR}/screenshots.log"

# Check if the dir to store the screenshots exists, else create it: 
if [ ! -d "${DIR}" ]; then mkdir "${DIR}"; fi 

# Screenshot a selected window
if [ "$1" = "win" ]; then import "${NAME}"; fi

# Screenshot the entire screen
if [ "$1" = "scr" ]; then import -window root "${NAME}"; fi

# Screenshot a selected area
if [ "$1" = "area" ]; then import "${NAME}"; fi

if [[ $# = 0 ]]; then
  # Display a warning if no area defined
  echo "No screenshot area has been specified. Screenshot not taken."
  echo "${DATE}: No screenshot area has been defined. Screenshot not taken." >> "${LOG}"
else
  # Save the screenshot in the directory and edit the log
  echo "${NAME}" >> "${LOG}"
fi

Remember to make the script executable:

# chmod +x /usr/bin/screenshot

Just run it with the argument "win" (for a screenshot of a certain window), "scr" (for a screenshot of the entire screen) or "area" (for a screenshot of the selected area).

Examples:

$ screenshot scr
$ screenshot win
$ screenshot area

The screenshots are stored in the directory ~/screenshots (it will be created if it does not exist yet) as screenshot-yyyymmdd@hhmmss.png (for example screenshot-20050904@192540.png).

If you have an image viewing program (i.e. gThumb), you can easily add a line at the bottom of the script so that the screenshot gets opened just after it has been made.

For gThumb, just add the following line at the bottom of the script:

gthumb "${NAME}"

WM/DE integration

In this chapter you will learn how to take screenshots with the PrintScreen key and through your favourite window manager menu.

Mapping the PrintScreen key

To figure out the keycodes for the PrintScreen key, issue the xmodmap -pke | grep -i print command (x11-apps/xmodmap package needed):

Code: $ xmodmap -pke | grep -i print
keycode 111 = Print Sys_Req

Otherwise you can use the xev command (from x11-apps/xev):

$ xev

Now we are going to map keycode 111 to a different keysym (F13 in this example, but any will work), and after that PrintScreen key will work just like it is supposed to:

$ xmodmap -e "keycode 111 = F13"

Also put the previous command in your ~/.xinitrc file, before the startfluxbox command:

File: ~/.xinitrc
xmodmap -e "keycode 111 = F13"

Specific WMs/DEs

Now read one of the following chapters, depending on the WM/DE you have:

Fluxbox

If you have Fluxbox, you can add these to your menu:

File: ~/.fluxbox/menu
...
[exec] (Screenshot Scr) {screenshot scr}
[exec] (Screenshot Win) {screenshot win}
[exec] (Screenshot Area) {screenshot area}
...

You can also create these keybindings:

File: ~/.fluxbox/keys
None F13 :execCommand screenshot scr
Mod1 F13 :execCommand screenshot win

Save, reconfigure, and use.

Openbox

If you have Openbox:

File: ~/.config/openbox/rc.xml
<keybind key="Print">
  <action name="Execute"><execute>/usr/bin/screenshot scr</execute></action>
</keybind>
<keybind key="C-Print">
  <action name="Execute"><execute>/usr/bin/screenshot win</execute></action>
</keybind>

Save, reconfigure, and use.

Enlightenment

If you have Enlightenment:

File: ~/.enlightenment/keybindings.cfg
...
      __KEY F13
      __EVENT __KEY_PRESS
      __MODIFIER_KEY __NONE
      __ACTION __A_EXEC /usr/bin/screenshot scr
  __NEXT_ACTION
      __KEY F13
      __EVENT __KEY_PRESS
      __MODIFIER_KEY __CTRL
      __ACTION __A_EXEC /usr/bin/screenshot win
  __NEXT_ACTION
...

Save, restart enlightenment and enjoy.

IceWM

The keys are stored in ~/.icewm/keys

This example actually uses Ctrl and Print Screen, and executes "scrot".

File: ~/.icewm/keys
key "Ctrl+Print" scrot

Remember to restart IceWM after making any changes to your preferences.

Xfce

Note: For versions <4.2 the shortcut settings are under Settings » Window Manager Settings » Keyboard Tab

For 4.4, in the Xfce menu, go to Settings » Keyboard Settings.

On 'default' the shortcuts are greyed out, so you will need create a new keyboard theme. To do so, just press the Add button, and enter the name for your new theme.

Now you can press the Add button under the list of current shortcuts. In the prompt, add the command, e.g. 'screenshot scr' (see above) and press OK. You will then be prompted for the shortcut key, and so simply press the key you want to use.

Alternatively there's a nifty Xfce screenshot panel plugin: xfce-extra/xfce4-screenshooter

GNOME and KDE

Both of these desktop environments have the Print Screen button already mapped to take a screenshot. GNOME will bring up an application (included in gnome-extra/gnome-utils) to save the shot, while KDE puts it in the clipboard (paste it in a Konqueror window or image editing application). You can also use Alt-Print Screen to take a single window. KDE has a application called ksnapshot that is included with kde-graphics. Run ksnapshot using Alt+F2 and it takes a screenshot and then asks if you would like to save it.

Others

If you do not have either of the above window managers, you can use xbindkeys for the same effect:

# emerge -av xbindkeys

Then add this to your ~/.xbindkeysrc file:

File: ~/.xbindkeysrc
"screenshot scr"
F13

"screenshot win"
control + F13

Save, run/reload xbindkeys and enjoy.

Links

From Gentoo Forums:

Places where to upload screenshots:


Last modified: Fri, 05 Sep 2008 23:34:00 +0000 Hits: 44,643