Monday, January 22, 2007

Bash script - Get screenshot

This little script gets a screenshot of your Apple box (runnig Os X), saves it to the ~/Desktop, renames it with the current date, and also makes a thumbnail of the image.
It gives you a few seconds before taking the screenshot.


#!/bin/sh
## -----------------------------------------------
## Gets a screenshot, after a timed delay
## (in seconds). Saves the screenshot to
## the LOC variable, and creates
## a thumbnail
## -----------------------------------------------
## Custom settings

## The filename
FILENAME="pb.screen.jpg"
THUMB_FILENAME="pb.screen_tn.jpg"

## Change the place where the script
## is stored, default is the Desktop
LOC="${HOME}/Desktop"

## The date format, it is non US
DATE=`/bin/date +%d-%m-%y_%H.%M.%S`

## Includes the cursor on the (captured) image
## Comment or delete the line below if you don't
## want it on your screenshots
CURSOR="-C"

## Customize this to the delay you want
DELAY="sleep 5"

## Thumbnails size
HEIGHT="480"
WIDTH="720"
## ------------------------------------------
## You shouldn't edit nothing below this line
## ------------------------------------------
GET_SCREEN="/usr/sbin/screencapture"
TYPE="-t jpg"
RESIZE_SCREEN="sips -z"
MV="mv -f"
CP="cp -f"

## Get the screenshot
$DELAY && $GET_SCREEN $CURSOR $TYPE && \
$MV jpg $FILENAME && $MV $FILENAME $LOC/$FILENAME

## Copy the screenshot to make a thumbnail
$CP ${LOC}/${FILENAME} ${LOC}/${THUMB_FILENAME}

${RESIZE_SCREEN} ${HEIGHT} ${WIDTH} ${LOC}/${THUMB_FILENAME}

## Time stamp the files
${MV} ${LOC}/${THUMB_FILENAME} ${LOC}/${DATE}.${THUMB_FILENAME}

${MV} ${LOC}/${FILENAME} ${LOC}/${DATE}.${FILENAME}

# EoF #

Labels: ,

0 Comments:

Post a Comment

<< Home