Automating screenshots
One of the boring tasks about documentation is taking screenshots, and update those as the software changes. So I looked for a way to remove this anti-DRY and found some interesting stuff to automate taking screenshots and do other things with X-Window and window managers:
* `xwininfo` and `xprop`: allows you to extract a lot of info of your running X apps, and convinces you to keep away from X-Window hacking ![]()
* `xrestop`: a top-like resource monitor for X-Window server resources being used by X clients
* `xlsclients`: lists X clients and shows more compact information than wxininfo/xprop
* `wmctrl`: a nice window manager control tool, that allows you to use “regexps” by default to match window titles
* `import`: a nice replacement for piped artifacts involving `xwd`, `xwdtopnm` and `pnmtopng` or `convert`. No more `xwd | xwdtopnm | pnmtopng > screenshot.png` or `xwd | convert xwd:- screenshot.png`
With those tools I made a small script that start an application, makes a screenshot and terminates it:
#!/bin/sh
do_screenshot () {
local TITLE=”$1″
local FILE=”$2″
local WIN=`wmctrl -l | grep “$TITLE” | cut -f1 -d’ ‘`
if [ "$WIN" -ne "" ] ; then
wmctrl -a $TITLE
rm $FILE
import -frame -border -window $WIN $FILE
if [ "$?" -ne "0" ] ; then
echo “import failed”
fi
fi
}
# TITLE is used as a “regexp” to identify application’s window
# FILE is used to store the screenshot
# SPAWN is used to run the application
# TERM is used to terminate the application
TITLE=”OpenOffice.org Writer”
FILE=”/tmp/foo.png”
SPAWN=”oowriter -norestore”
TERM=”killall soffice.bin”
$SPAWN
sleep 2
do_screenshot “$TITLE” $FILE
$TERM
It needs some tweaking and is a kind of “brute force” (e.g. killall
), but it’s easy and works…
About this entry
You’re currently reading “Automating screenshots,” an entry on Catarsis
- Published:
- 05.03.08 / 5pm
- Category:
- Engineering, Free Software
No comments
Jump to comment form | comments rss [?] | trackback uri [?]