3 # Copyright (C) 2013 by Werner Lemberg.
5 # This file is part of the ttfautohint library, and may only be used,
6 # modified, and distributed under the terms given in `COPYING'. By
7 # continuing to use, modify, or distribute this file you indicate that you
8 # have read `COPYING' and understand and accept it fully.
10 # The file `COPYING' mentioned in the previous paragraph is distributed
11 # with the ttfautohint library.
14 # make-snapshot.sh <application> <filename>
16 # Make a snapshot from an application's start window and save it to a file.
17 # This needs X11 and ImageMagick's `import' tool.
19 # This script is very simple. Some possible problems:
21 # o In case the program doesn't create a visible X11 window, you have to
22 # abort the script with ^C.
24 # o It fails for intelligent applications like `firefox' in case they are
25 # already run, since firefox replaces the process with a new window of the
26 # already running instance.
28 # o It loops forever for programs like `k3b' which spawns itself, thus
29 # having a different process ID for the visible window.
32 # This script uses ideas from
33 # http://blog.chewearn.com/2010/01/18/find-window-id-of-a-process-id-in-bash-script/.
36 echo "Usage: $0 application imagename"
43 # Get all windows with the name $APP (ignoring case).
44 xwininfo
-root -tree 2>/dev
/null \
48 WID
=`echo $DATA | awk '{print $1}'`
50 # Check whether the window's PID is matching the application's PID.
51 if [ `xprop -id $WID _NET_WM_PID | awk '{print $3}'` -eq $PID ]; then
52 # Check whether window is displayed actually.
53 if [ "`xwininfo -id $WID | grep 'IsViewable'`" != '' ]; then
62 # Start program in background and get its process ID.
68 # Get application name.
69 APP
=`ps --no-header -o comm -p $PID`
70 if [ "$APP" == "" ]; then
71 echo "Couldn't start application \`$1'"
75 # Loop until program has displayed a window
76 # so that we can actually get the Windows ID.
77 while [ "$WID" == "" ]; do
83 import
-silent -window $WID $2