From 1ff13adfd6b2dc328a0f4e82eea5e09000b8db6f Mon Sep 17 00:00:00 2001 From: Glyph Date: Mon, 20 Dec 2021 22:53:44 -0800 Subject: [PATCH 1/4] requirements files --- requirements.in | 1 + requirements.txt | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 requirements.in create mode 100644 requirements.txt diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..162cf1a --- /dev/null +++ b/requirements.in @@ -0,0 +1 @@ +pyobjc-framework-Quartz diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bef65ff --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +# +# This file is autogenerated by pip-compile with python 3.10 +# To update, run: +# +# pip-compile requirements.in +# + +pyobjc-core==8.1 + # via pyobjc-framework-quartz +pyobjc-framework-cocoa==8.1 + # via pyobjc-framework-quartz +pyobjc-framework-quartz==8.1 + # via -r requirements.in From 84858e942eef6283cd7b3f1509c6e6dd188eb195 Mon Sep 17 00:00:00 2001 From: Glyph Date: Mon, 20 Dec 2021 22:54:42 -0800 Subject: [PATCH 2/4] python3 --- lswin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lswin.py b/lswin.py index 830d8de..62ffd3b 100755 --- a/lswin.py +++ b/lswin.py @@ -9,8 +9,8 @@ #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-------------------------------------------' +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 ( \ @@ -27,4 +27,4 @@ '}' + \ '\t[' + ((v.valueForKey_('kCGWindowOwnerName') or '') + ']') + \ ('' if v.valueForKey_('kCGWindowName') is None else (' ' + v.valueForKey_('kCGWindowName') or '')) \ - ).encode('utf8') + ) From ab55ae61c224d11ad47eda9cdad24ccc626ea86c Mon Sep 17 00:00:00 2001 From: Glyph Date: Mon, 20 Dec 2021 22:54:54 -0800 Subject: [PATCH 3/4] apply Black --- lswin.py | 72 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/lswin.py b/lswin.py index 62ffd3b..9ef10e4 100755 --- a/lswin.py +++ b/lswin.py @@ -2,29 +2,59 @@ import Quartz -#wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionOnScreenOnly | Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID) -wl = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionAll, Quartz.kCGNullWindowID) +# 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')) +wl = sorted(wl, key=lambda k: k.valueForKey_("kCGWindowOwnerPID")) -#print wl +# 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-------------------------------------------') +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 '')) \ - ) + 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 "") + ) + ) From e0dd8a3510d3447f843c7ab8aa229d75c7f99b2f Mon Sep 17 00:00:00 2001 From: Glyph Date: Mon, 20 Dec 2021 22:59:49 -0800 Subject: [PATCH 4/4] fix README to update to current state of things --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 277cf31..d9f4fcc 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# mac_list_windows_pids +# `mac_list_windows_pids` Mac OS X: list all windows title and their owner process ids -##Usage: +## Usage: -Tested on OS X Yosemite 10.10.5, Python 2.7 +Tested on macOS Monterey 12.2, Python 3.10.0 -*Note* if you run into error `No module named Quartz`, then run `pip install pyobjc-framework-Quartz` to install it. +*Note* if you run into error `No module named Quartz`, then run `pip install -r requirements.txt` to install it. $ python lswin.py @@ -39,7 +39,7 @@ Tested on OS X Yosemite 10.10.5, Python 2.7 ... ... -##Known problems +## Known problems Processes created by Safari browser will be displayed as same PID as main Safari process.