Kalmat / PyWinCtl

Cross-Platform module to get info on and control windows on screen
Other
180 stars 19 forks source link

MacOS pywinctl.getAllWindows(None) misses a lot of windows #21

Closed Avasam closed 1 year ago

Avasam commented 2 years ago

This prevents getWindowsAt from catching some very obvious windows. It totally misses Chrome, Firefox, the Terminal, and probably much more.

The private functions _getAllWindows and _getWindowTitles do actually get the browsers and terminal.
_getAllApps however, does not (even with userOnly=False). Looking at getAllWindows's implementation, it seems it needs a matching pID from both _getWindowTitles and _getAllApps.

So it all goes back to AppKit.NSWorkspace.sharedWorkspace().runningApplications() not returning some applications because... reasons 🤷

Kalmat commented 2 years ago

Hi! This sounds very weird to me. I'm absolutely sure it was returning all windows and apps. Which macOS version you have? (just to try to replicate your very same enviroment). Unfortunately, I don't own a "real" mac, and these days I have no access to my virtual machines. I will test and, if needed, modify all these methods as soon as I can!

Thank you so much for your comments and help.

Avasam commented 2 years ago

I'm using a Virtual Machine as well. This one is on 11.0.1

Kalmat commented 2 years ago

Hi! Is this still happening to you? I am trying to get a 11.0.1 version to test on it. Testing on Catalina, no app or window is missed!

getAllTitles() ['Google Chrome', 'Descargas', 'Proyectos', 'pywinctl — osascript ◂ Python _pywinctl_macos.py — 80×24', 'Navegador web Google\xa0Chrome', '', 'Contacts', 'App\xa0Store', 'Te damos la bienvenida a Chrome - Añade marcadores a tus aplicaciones de Google favoritas - Google Chrome']

getAllWindows()

Google Chrome
Descargas
Proyectos
pywinctl — osascript ◂ Python _pywinctl_macos.py — 80×24
Navegador web Google Chrome

Contacts
App Store
Te damos la bienvenida a Chrome - Añade marcadores a tus aplicaciones de Google favoritas - Google Chrome

(the empty title is an open contact, which do not have any window title... yes, macOS is wonderful)

_getAllApps()

Finder
Terminal
Safari
Contactos
App Store
Google Chrome
Python

_getAllAppsWindowsTitles()

{'Finder': ['Google Chrome', 'Descargas', 'Proyectos'], 'Terminal': ['pywinctl — osascript ◂ Python _pywinctl_macos.py — 80×24'], 'Safari': ['Navegador web Google\xa0Chrome'], 'Contacts': ['', 'Contacts'], 'App Store': ['App\xa0Store'], 'Google Chrome': ['Te damos la bienvenida a Chrome - Añade marcadores a tus aplicaciones de Google favoritas - Google Chrome'], 'Python': []}

Kalmat commented 2 years ago

Hi again! I hope you're doing well! I eventually managed to install BigSur. The results I get are the same than in Catalina, so totally lost here about what might be happening in your case.

getAllTitles() ['Aplicaciones', 'pywinctl — osascript ◂ Python _pywinctl_macos.py — 80×24', 'Navegador web Google Chrome', 'Apple Inc.', 'Contacts', 'Te damos la bienvenida a Chrome - Google Chrome']

getAllWindows() - Printing titles

Aplicaciones
pywinctl — osascript ◂ Python _pywinctl_macos.py — 80×24
Navegador web Google Chrome
Apple Inc.
Contacts
Te damos la bienvenida a Chrome - Google Chrome

_getAllWindows() - Printing "kCGWindowOwnerName" (app name)

Google Chrome
Google Chrome
Google Chrome
Google Chrome
Google Chrome
Google Chrome
Google Chrome
CoreServicesUIAgent
Finder
Safari
Safari
Safari
Safari
Safari
Safari
Safari
Contactos
Contactos
Contactos
Contactos
Contactos
Contactos
Contactos
Window Server
Window Server
Terminal
Centro de control
Centro de control
Terminal
Finder
Terminal
Finder
Finder
Terminal
Finder
Terminal
Finder
Centro de control
Safari
Terminal
Finder
Contactos
Terminal
Spotlight
Dock
Dock
Finder
Centro de control
Window Server
TextInputMenuAgent
Spotlight
Centro de notificaciones

getAllAppsWindowsTitles() {'Finder': ['Aplicaciones'], 'Terminal': ['pywinctl — osascript ◂ Python _pywinctl_macos.py — 80×24'], 'Safari': ['Navegador web Google Chrome'], 'Contacts': ['Apple Inc.', 'Contacts'], 'Google Chrome': ['Te damos la bienvenida a Chrome - Google Chrome'], 'Python': []}

Avasam commented 2 years ago

I'm not in a place where I can try again right now. But next week I'll try to investigate a bit (like trying on a different install, making sure everything is up to date, etc.)

Kalmat commented 1 year ago

Hi again! Sorry to bother you. Did you have the time to test this? Is the issue still there? Please, let me know whenever you have any comment or progress.

Thank you!

Avasam commented 1 year ago

Using a macos VM was such an awful experience, I dusted off my old 2009 macbookpro and updated it (w/ unofficial patches) to 11.7.1 And all windows are reported now! So it could be something that was fixed somewhere between 11.0.1 and 11.7.1.

Likely an (old) AppKit bug