s/DUMP/DUMPVAL/.
[ttfautohint.git] / doc / make-snapshot.sh
blob0a5fa2b76887ebfcbeb71e10bf4dd421b10d46cb
1 #! /bin/sh
3 # make-snapshot.sh <application> <filename>
5 # Make a snapshot from an application's start window and save it to a file.
6 # This needs X11 and ImageMagick's `import' tool.
8 # This script is very simple. Some possible problems:
10 # o In case the program doesn't create a visible X11 window, you have to
11 # abort the script with ^C.
13 # o It fails for intelligent applications like `firefox' in case they are
14 # already run, since firefox replaces the process with a new window of the
15 # already running instance.
17 # o It loops forever for programs like `k3b' which spawns itself, thus
18 # having a different process ID for the visible window.
21 # This script uses ideas from
22 # http://blog.chewearn.com/2010/01/18/find-window-id-of-a-process-id-in-bash-script/.
24 if [ $# -ne 2 ]; then
25 echo "Usage: $0 application imagename"
26 exit 1
30 find_WID()
32 # Get all windows with the name $APP (ignoring case).
33 xwininfo -root -tree 2>/dev/null \
34 | grep -i $1 \
35 | while read DATA; do
36 # Extract Window ID.
37 WID=`echo $DATA | awk '{print $1}'`
39 # Check whether the window's PID is matching the application's PID.
40 if [ `xprop -id $WID _NET_WM_PID | awk '{print $3}'` -eq $PID ]; then
41 # Check whether window is displayed actually.
42 if [ "`xwininfo -id $WID | grep 'IsViewable'`" != '' ]; then
43 echo $WID
44 return
47 done
51 # Start program in background and get its process ID.
52 $1 &
53 PID=$!
55 sleep 1
57 # Get application name.
58 APP=`ps --no-header -o comm -p $PID`
59 if [ "$APP" == "" ]; then
60 echo "Couldn't start application \`$1'"
61 exit 1
64 # Loop until program has displayed a window
65 # so that we can actually get the Windows ID.
66 while [ "$WID" == "" ]; do
67 WID=`find_WID $APP`
68 sleep 1
69 done
71 # Make snapshot.
72 import -silent -window $WID $2
74 kill $PID
76 # eof