-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apple Silicon MacOS getActiveWindowTitle() large latency #84
Comments
Hi! As you can read in the README page... (HAHAHAHA! Nobody does, I know, including myself!)
This is really annoying, but this is all we can do when on macOS, sorry for the bad news. The difference in performance is because, on macOS, you have to open a terminal, load the script interpreter, run the script, return the values... 400-500ms as result. I hope you can manage to find a workaround. Just let me know! |
Hi Kalmat! Thanks for the timely response. I realized that the getActiveWindowTitle() function for macos is using Applescript and I actually tried running a less complex Applescript to get the app's title in Python. The latency for that is still too high for me, around 250ms. Later, I found an alternative to get the application name (not the window name but the app's name) using AppKit.
With this, I can get the the current application's name within 1ms latency on a Macbook M1 pro. Thanks! |
Hi again! Thank you for your help! I forgot to mention that In addition to that, PyWinCtl is intended to get info and control windows, not apps. You can use As far as I could find, the only way to manipulate other apps' windows in macOS is using AppleScript. The AppKit app object will not let you change any property. Besides, getting the title of the app can be enough for mono-window apps, but not for multi-window apps (e.g. TextEdit will return 'TextEdit' when invoking app.localizedName(), but the active window title will be something like "TextEdit - " + "the-name-of-the-doc-you-are-editing"). In your case, if you just need the name of the active app, you can use the snippet you attached, which is way faster!! Just bear in mind that for non-English languages the localizedName() might be different (e.g. in Spanish localizedName() method for the app "Contacts" will return "Contactos") Thank you again for your help and interest! Just let me know any thought or improvement you can find!!! |
Hi there, sorry for bumping an old thread, but is there anyway to get individual window titles from multi-window apps? I am looking to find multiple windows of the same bundle and get their window titles independently. |
Hi there! Sorry for my late reply. I have limited access to my development stuff these days. Don't worry about bumping, though it is better for other users to open separate posts for separate issues. In your case, using
In a very simple scenario, the output is as follows:
Note that TextEdit returns two windows (I already opened two empty docs in separate windows). whilst Safari only returns the active tab (there were several actually open, but just one visible). Hope this helps! |
Howdy, thanks for responding and sorry for my late response. So, fun fact, it seems that if a macOS app/window is full screened (in my case, two instances of a particular app), there's no window title: >>> pprint(pwc.getAllAppsWindowsTitles())
...
'exefile': [], however if they are both windowed, there is in fact a window title: 'exefile': ['EVE - Draconic Slayer'], This is quite inconvenient for my use-case. I'm trying to setup a program where I can setup hotkeys to swap to a particular fullscreened window/app/whatever, however there's multiple instances of Separately, and this may warrant a new issue, it seems to only update the windows I have open once-per-restart. This doesn't sound like an issue with pywinctl, though. I just opened a few more instances of my app (exefile), but they did not populate in the above function call (when repeated). |
Hi! In my case, the behaviour is the opposite: when a window is maximized, then it is the only one found when using Testing this simple script in Big Sur (sorry, I have no access to a more modern version):
The output is (I maximized the "TextEdit - Sin título" window while the script was running):
This is can be very inconvenient in some use cases... I have to figure out how to fix it. I suspect the key is in this condition I use within AppleScript to avoid showing non-user (system) processes: I don't know if this all helps you in any way, but according to your explanation, you should be able to find the maximized window (and only that one). If this not the case, please let me know so I can try to help you. In the meantime, I will try to figure out the "good" solution... if any. |
Following is the code I used in my case:
I ran this on a M1 Macbook pro. The latency is around 400ms to 500ms to just get the active window.
I ran this on another windows machine, the same code gave a latency around 1ms to almost none latency.
May I ask why does the performance vary this much? Or is there something I should do in MacOS for it run smoother?
The text was updated successfully, but these errors were encountered: