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/.
25 echo "Usage: $0 application imagename"
32 # Get all windows with the name $APP (ignoring case).
33 xwininfo
-root -tree 2>/dev
/null \
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
51 # Start program in background and get its process ID.
57 # Get application name.
58 APP
=`ps --no-header -o comm -p $PID`
59 if [ "$APP" == "" ]; then
60 echo "Couldn't start application \`$1'"
64 # Loop until program has displayed a window
65 # so that we can actually get the Windows ID.
66 while [ "$WID" == "" ]; do
72 import
-silent -window $WID $2