6

I've got this code to list all windows (including full screen windows):

#!/usr/bin/python
# Prints list of all windows.
import Quartz
for window in Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListOptionOnScreenOnly & Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID):
    print("%s - %s (PID: %d, WID: %d, Pos: %dx%d, Size: %dx%d)"
        % (
            window['kCGWindowOwnerName'],
            window.get('kCGWindowName', u'(empty)').encode('ascii','ignore'),
            window['kCGWindowOwnerPID'],
            window['kCGWindowNumber'],
            window['kCGWindowBounds']['X'],
            window['kCGWindowBounds']['Y'],
            window['kCGWindowBounds']['Width'],
            window['kCGWindowBounds']['Height'],
            ))

Here is the sample output:

$ ./get_window_list_all.py | grep BlueStacks
BlueStacks - BlueStacks App Player (PID: 28084, WID: 42238, Pos: 0x0, Size: 1920x1200)

Now I'd like to get visual content (e.g. image) of specific window from whenever workspace it is currently. I could use CGWindowListCreateImage (as shown here), but the window is not visible in the current workspace as it's in full screen mode, secondly this function is returning combined image from all windows (so it won't work if window is behind another window).

Is there any more relevant function which I can use to get image/screenshot of specific window based on its window ID despite its location (from any workspace/desktop) and whether it's shown or hidden?

kenorb
  • 155,785
  • 88
  • 678
  • 743

0 Answers0