October 20, 2007 Archives

Sat Oct 20 21:35:33 CDT 2007

Using ImageMagick to take screenshots in Linux

There are many reasons to take a screenshot of your computer.
  • Proof of an event
  • Easy way to describe an error to a tech
  • Check on a computer remotely
  • Document a computer activity like software installation.


I used to run a cron job at work to take screenshots at random intervals so that I could get an overview of the ammount of time I spent on different tasks. It was also a handy way to log which clients' sites I had viewed.

More recently, I noticed that bashcurescancer switched from it's striking console-sytle black background to a more standard color scheme. At first glance I thought the domain had expired and this was a registrar landing page. Thinking that it might display differently on my work pc in IE than it had in Firefox at home, I decided to check it out.

Since I didn't have access to a Linux machine at the office, I had to do it remotely. I used ssh to connect to my home network and then to my laptop. I gave the command to launch a Firefox tab with the page and waited for it to load.

This is the script that I used to save screenshots:
#!/bin/bash
##########
#These next lines are helpful to prevent GTK errors 
#otherwise it doesn't seem to get the right permissions.
##########
DISPLAY=:0
export DISPLAY
HOME=/home/nesman
export HOME
##########
import -window root -geometry 800x600 -silent /mnt/hd/samson/backup/screenshots/`date +%b%d%a%H%M`.jpg

To make it easy to see my screenshots, I saved them to an NFS share from my server, Samson. Then, I ssh'd to the server and symlinked the screenshots directory into my web directory.
ln -s /mnt/hd/spare/screenshots htdocs/screenshots

This creates a web directory named screenshots so that I can browse to my screenshot or any new images.

Next time I'll go over the code that I use to fire up Firefox remotely.

Posted by Nesman | Permanent Link