Home

Roy Schestowitz

Screen (Display) Grabber

The Purpose

The page outlines a simple way of making public 'reflection' of your display (screen/s or monitor/s). This puspose of this network of scripts is to make such a reflection possible without user intervention, i.e. everything should happen in the background. Perferably, this should also run without affecting other processes currently running.

To see an example of the output, have a look at the bottom of the introduction page. As well as a current snapshot of the display being public, a series of daily screenshots can be retained and made public. Moreover, timestamps get assigned to images and processes currently running can be shared with the public (not highly recommended though).

Basic Instructions

  • Set up public_html (a public space) on a UNIX/Linux/MAC OS X box. Windows users may take advantage of alternatives like Cygwin, which emulate the same feature on a Windows-based PC.
  • You may use a wizard to set up a Web server, typically on port 8001 and the standard location which is ~/public_html (your home directory's public domain). The permissions on ~/public_html must accept it as public, e.g. by typing chmod 755 ~/public_html at the command-line.
  • Under KDE, if you have not got public_html set up already, you might wish to right-click (right-handed mouse) on one of the panels (docks), then follow Add » Applet » Public File Server. From there onwards, a wizard will guide you through the short and painless process.
  • Having got a public space on your machine, create a file called grab_screen.sh (e.g. under the directory ~/Scripts/) and have it contain the following:

#!/bin/sh

export DISPLAY=localhost:0.0
    # set display (to make cron job work)
import -window root ~/public_html/screen-temp.jpeg
    # capture display
mogrify -resize 25% ~/public_html/screen-temp.jpeg
    # save to temporary file so as to avoid full-sized
    # image from being public for a second
cp ~/public_html/screen.jpeg ~/public_html/screen-previous.jpeg
    # save the previous screenshot
mv ~/public_html/screen-temp.jpeg ~/public_html/screen.jpeg
    # below are bits that write information to a simple text file
echo "Refresh cycle is currently set to 10 minutes" > ~/public_html/caption.txt
echo "" >> ~/public_html/caption.txt
echo "Image last captured on: " >> ~/public_html/caption.txt
date >> ~/public_html/caption.txt
echo "" >> ~/public_html/caption.txt
TERM=linux
export TERM
top -b -n 1 >> ~/public_html/caption.txt
    # The line above exposes plenty. Replace the above line with
    # echo "List of processes omitted" >> ~/public_html/caption.txt
    # to block it altogether
echo "" >> ~/public_html/caption.txt
echo "______________________________________________" >> ~/public_html/caption.txt
echo "Script by Roy Schestowitz, August 2005" >> ~/public_html/caption.txt


Note: Some of the commands listed above require Image Magick, which is included in most (if not all) *NIX distributions from the very start.

  • Set up a cron job to execute the script every 10 minutes, e.g.:
    10,20,30,40,50,0 * * * * /home/[user]/Scripts/grab_screen.sh
    The names of files and directories can be changed, of course. The names above are for illustrational purposes and for consistency across this explanatory page.

  • Link to the image in ~/public_html/screen.jpeg using the following example (X)HTML code:
    <img src="Your machine address (namescape or IP address):8001/screen.jpeg" alt="Computer switched off at the moment" />
    <img src="Your machine address (namescape or IP address):8001/screen-previous.jpeg" alt="Computer switched off at the moment" />
    Note that the alt attrribute will only be used when the computer is not connected or switched off, hence the message which will substitute the image.

  • Link to the caption in ~/public_html/caption.txt using the following example (X)HTML code:
    <a href="Your machine address (namescape or IP address):8001/caption.txt">Information about the image and machine state</a>

Archives

The retain archives of daily screenshots, the ideas remain similar, but general changes are made (often mere simplifications of the above).

Code

Set up a new script file with the filename grab_screen_archive.sh, it should contain the following code:


#!/bin/sh

export DISPLAY=localhost:0.0
    # set display (to make cron job work)
import -window root ~/public_html/archive/screen-temp.jpeg
    # capture display
mogrify -resize 18% ~/public_html/archive/screen-temp.jpeg
    # save to temporary file so as to avoid full-sized
    # image from being public for a second
mv ~/public_html/archive/screen-temp.jpeg ~/public_html/archive/screen-`date +%Y-%m-%d-%H`.jpeg

Cron Job

The capture cycle will now be different. Since all screen grabs get saved, their number needs to be reasonable, or else you would run out of space quickly. Below is a cron job that will invoke the script once a day.


0 10 * * * nice /home/[user]/Scripts/grab_screen_archive.sh

This will register a screenshot every morning at 10. Ensure that grab_screen_archive.sh is executable and that ~/public_html/archive has writing persmissions.

Linking to Archive Directory

As before, you may wish to add code to link to the actual archive from a public page:


<a href="Your machine address (namespace or IP address):8001/archive">Daily Archive</a>

Epilogue and Other Tools

This page described a method for keeping track of desktop usage history. It is essentially a log of the user's wallpapers, applications and general look-and-feel, which later in life will have a nostlagic value. If you wish to keep track of music that you listen to you, have a look at the music log files page as well.


This page was last modified on August 22nd, 2005 Maintained by Roy Schestowitz