I made a tool named lswin
$ python lswin.py
PID WinID x,y,w,h [Title] SubTitle
------- ----- --------------------- -------------------------------------------
169 1956 {0,-38,1280,25 } [Window Server] Backstop Menubar
169 1955 {0,-60,1280,22 } [Window Server] Menubar
169 396 {0,-38,1280,25 } [Window Server] Backstop Menubar
169 395 {0,-60,1280,22 } [Window Server] Menubar
169 6 {0,0,0,0 } [Window Server] Cursor
169 4 {0,22,1280,25 } [Window Server] Backstop Menubar
169 3 {0,0,1280,22 } [Window Server] Menubar
169 2 {0,0,1280,800 } [Window Server] Desktop
262 404 {0,-38,1280,38 } [Google Chrome]
262 393 {0,0,1280,800 } [Google Chrome]
262 380 {100,100,1,1 } [Google Chrome] Focus Proxy
... ...
Then you can use grep to find your window's pid.
Here is the source code of the script:
#!/usr/bin/env python
import Quartz
#wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionOnScreenOnly | Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID)
wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionAll, Quartz.kCGNullWindowID)
wl = sorted(wl, key=lambda k: k.valueForKey_('kCGWindowOwnerPID'))
#print wl
print 'PID'.rjust(7) + ' ' + 'WinID'.rjust(5) + ' ' + 'x,y,w,h'.ljust(21) + ' ' + '\t[Title] SubTitle'
print '-'.rjust(7,'-') + ' ' + '-'.rjust(5,'-') + ' ' + '-'.ljust(21,'-') + ' ' + '\t-------------------------------------------'
for v in wl:
print ( \
str(v.valueForKey_('kCGWindowOwnerPID') or '?').rjust(7) + \
' ' + str(v.valueForKey_('kCGWindowNumber') or '?').rjust(5) + \
' {' + ('' if v.valueForKey_('kCGWindowBounds') is None else \
( \
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('X'))) + ',' + \
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Y'))) + ',' + \
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Width'))) + ',' + \
str(int(v.valueForKey_('kCGWindowBounds').valueForKey_('Height'))) \
) \
).ljust(21) + \
'}' + \
'\t[' + ((v.valueForKey_('kCGWindowOwnerName') or '') + ']') + \
('' if v.valueForKey_('kCGWindowName') is None else (' ' + v.valueForKey_('kCGWindowName') or '')) \
).encode('utf8')
“…which process is showing which window…” This is confusing when compared to your Windows example of “…which DLL/program was using the webcam by searching for a DLL or substring.” Can you please edit your question to clarify. – JakeGould – 2015-04-17T18:20:08.603
1Some processes are running without any windows, and perhaps even without a controlling terminal. – Basile Starynkevitch – 2015-04-17T19:09:21.627