Remember what you did a few days ago on your Linux computer

I am busy like most people throughout the day and switch tasks often. Taking good notes during my work is tedious and there are times when I forget or cannot and I lose knowledge this way. I lose the  steps leading to solutions, I forget to record some item for billing purposes or I need to verify the length of time I spent doing something. What I want is someway to automatically take a snapshot of my monitor screen(s) producing a time stamped image. There are solutions in Windows and for Mac but none that I found for  Linux.

Shots folder

First, there’s a top-level folder I call shots as in snapshot that

Folder holding daily folders of images

holds all the folders for each days worth of images. The location and name of this folder can be changed in the script. I keep it in my home folder for convenience.

Daily folders
Each day the script checks for a folder to hold the images and if it doesn’t exist it creates it. The name of the daily folder is the date. Over time these folders will collect and build up taking valuable disk space. You should delete the oldest of these folders as a matter of good disk hygiene. Then again the script could be modified to search for folders that are older than a configurable number of days and remove the image contents and the folders.

Folders created every day containing images

Images
Desktop images are snapped in the current script every 300 seconds or 5 minutes and dropped into the daily folder in the shots folder. Scrot is configurable through the command line giving you the ability to reduce resolution of images, for instance, thereby reducing the size and clarity of the images if that’s a concern.

Inside a daily folder

Scrot has other configurable parameters so you should read the man page at least.

Here’s how you solve this in Linux. The recipe is simple:

  • 1 – screen capture utility
  • 1 – shell script

Fulfilling the first item, what we need is as simple screen capture utility to take a snapshot every so often and place the image in a known location. So there’s a single folder containing date stamped folders and each date stamped folder contains date and time stamped images. How do we do this? There are several utilities and applications in the Linux world that can take screen captures. The simple one that free that does the job more than adequately is SCROT. For Ubuntu,

sudo apt-get install scrot

Using scrot, it takes a screen capture, labels it with the date and time and move it into a known directory. It’s accomplished this way:

scrot ‘%Y-%m-%d_%H:%M:%S_$wx$h.png’ -e ‘mv $f ‘”$DIRECTORY”

Where $DIRECTORY is the path to a directory of your choosing.

Executing this command line yields a file named:

2012-07-24_18:56:14_1600x900.png

if executed on 7/24/2012 at 6:54. The photo is a 1600×900 pixel PNG file.

This works well. Then next and final thing to do in our recipe is create a shell script that periodically executes this command and each day change the date stamp. Here the bash shell script:


#!/bin/bash
# TODAY - today's date.
# DIRECTORY - directory to store the image in; ours is 'shots'.
TODAY=$(date +"%Y-%m-%d")
DIRECTORY="$HOME/shots/$TODAY"
# Repeat forever.
while true;
do
# If the directory does not exist, create it.
if [ ! -d "$DIRECTORY" ]; then
mkdir $DIRECTORY
fi
# take a shot and name it with a timestamp and move the shot
# to the 'shots' folder.
scrot '%Y-%m-%d_%H:%M:%S_$wx$h.png' -e 'mv $f '"$DIRECTORY"
# do again
sleep 5m
done

This script is setup to automatically run when you log in or is run manually, your choice.

 


Leave a Reply

Your email address will not be published. Required fields are marked *