How do I use screencapture for capturing floating windows?

I am trying to automate the periodic capture of a floating window. Specifically, of the floating 'Current Call' window which is used by Skype when the main window is off-screen.

By googling, I found out that all I need is a window id to pass to screencapture:

screencapture -l<win_id> <output_file>

The problem is that I haven't found a way to get the window id for "Current Call". Here is what I have tried so far:

$ osascript -e 'tell app "Skype" to id of first window whose floating is true'
20:61: execution error: Skype got an error: Can’t get window 1 whose floating = true. Invalid index. (-1719)
$ osascript -e 'tell app "Skype" to id of first window whose name is "Current Call"'
20:67: execution error: Skype got an error: Can’t get window 1 whose name = "Current Call". Invalid index. (-1719)

Does anyone know how to get the window id for the "Current Call" window?

Or, alternatively, does anyone know if I can get this screenshot in some other way? (e.g. run screencapture with other arguments, or use some other tool for capturing the screenshot)


Update

I have also tried the following:

$ osascript -e 'tell app "Skype" to id of window 0'
-1
$ osascript -e 'tell app "Skype" to id of window 1'
-1
$ osascript -e 'tell app "Skype" to id of window 2'
84
$ osascript -e 'tell app "Skype" to id of window 3'
20:22: execution error: Skype got an error: Can’t get window 3. Invalid index. (-1719)

Window with id 84 is the main skype window. So, I'm a bit puzzled here. What is -1 supposed to mean?


Solution 1:

I wrote a command line utility that wraps over screencapture and the Quartz windowing library.

Grab it here: https://github.com/thismachinechills/pyscreencapture

Use it like this:

./screencapture.py Skype -t Current Call -w all_windows above_window