Closed PB101010 closed 2 years ago
Hi! Thank you for your comment. You are totally right. Some apps (e.g. Terminal) may change the title. Very interesting and tricky issue I was trying to figure out the best solution.
Regarding "in" vs. "==", a window title may contain part of the title you are looking for. If so, you would obtain the window you're really looking for (the one which eventually has slightly changed its title), together with others you are not interested at all, e.g. Terminal (system console) and Terminal (the film).
On the other hand, Apple Script version uses title as the "id" for the window in all methods. If we could use the new title, then it could address a different window. If we don't, then it might become useless... Taking also into account that it is totally impossible using Apple Script to detect a title change, my choice then was to stick to the original title and let the developer to decide wether to refresh the window object if needed or not.
In both cases, the decission was to stick to the exact original title. I am very interested to know what you think on this to have as many points of view as possible.
I'm tyro in both python and Mac (Apple Script is much more like magic to me), seems on mac it works trickiness than I throught. but new title method works for my problem (mainly to bring Chrome active), if can't change is totally ok to me, i change it in my local Mac will also work, thanks for your concern sir
You're welcome! Do not hesitate to contact again with any issue, comment or suggestion.
I am reopening this issue just to give you a suggestion for the problem you were mentioning. If you need a "in"-like search, you can do the following:
targetTitle = "Chrome"
titles = pywinctl.getAllTitles()
for title in titles:
if targetTitle in title:
windows = pywinctl.getWindowsWithTitle(title)
if windows:
win = windows[0]
# Do your stuff with win object
Hope this helps!
Hi again! macdeport gave me a very good idea to address this issue. I will work on it soon, so please pay attention to new versions (probably v0.0.32) which will include regex-style (equal, contains, startswith, endswith) options to search for windows titles. Any idea or suggestion you may have, is totally welcome.
regex-style (equal, contains, startswith, endswith) ------------- this is super, appriciate for your effort :)
Thank you for your kind words! I will be adding some more options soon. Happy to hear it's useful!
in _pywinctl_macos.py , method, getWindowsWithTitle
line 138. # if winTitle and winTitle == title:
better change to title in winTitle , since some app's title always change based on different content.