Wednesday, 8 May 2013

screenshots in linux

Use xev to determine the keycode for printscreen.

Edit ~/.fluxbox/keys to include,

118 :execCommand /home/me/bin/screenshot scr

if keycode 118 is appropriate.  Create the following file, ~/bin/screenshot:



#!/bin/bash
# from http://gentoo-wiki.com/TIP_Make_a_Screenshot_with_PrintScreen_Key
# call as screenshot scr  or  screenshot win  or  screenshot area
# Saves to folder, ~/screenshots/,  making it if required.
# Map to printscreen key, keycode 111 by mapping it to F13 in ~/.xinitrc by adding, 
# xmodmap -e "keycode 111 = F13" before fluxbox is called.
# Then add the line, 'None  F13  :execCommand screenshot scr' to ~/.fluxbox/keys

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


Thanks blogger, for the mangling.  This was from the gentoo-wiki, 
as mentioned above.

No comments:

Post a Comment