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
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.
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,
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:
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.