Skip to content
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

Add capability to focus window by title #1262

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pturpin
Copy link

@pturpin pturpin commented Sep 15, 2023

Problem

When an app has multiple windows focus just picks the first one it fights, which may not be the desired one, and there is not a great way to focus just the window you want.

Solution

Add a new method, switcher_focus_app_title, to app_switcher.py that will focus the window whose title matches a given app name and a given regular expression. Also added a command to that will focus a window with a given spoken phrase.

Testing

Verified working in current windows eleven environment.

pturpin and others added 2 commits September 15, 2023 14:22
#Problem
When an app has multiple windows focus just picks the first one it fights, which may not be the desired one, and there is not a great way to focus just the window you want.

#Solution
Add a new method, switcher_focus_app_title, to app_switcher.py that will focus the window whose title matches a given app name and a given regular expression. Also added a command to that will focus a window with a given spoken phrase.

#Testing
Verified working in current windows eleven environment.
and window.title != ""
):
# logging.warn(f'Checking Window: "{window.app.name}" window:"{window.title}" hidden: "{window.hidden}"')
if regex is None or re.search(regex, window.title):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your usecase for passing a regex here?

Copy link
Author

@pturpin pturpin Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I currently have two commands that utilize an actual regex vs a plain string.

  1. Where the app title could contain one of two different things.
    focus outlook: user.switcher_focus_app_title("Outlook", "(Inbox|Calendar)")

  2. When I don't want the title to contain a specific string.
    focus studio: user.switcher_focus_app_title("Microsoft Visual Studio", "^(?:(?!Application Management).)*$")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this seems reasonable given the use cases. @auscompgeek any objection or you think it's ok?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the use-case makes sense. I'm not sure we should make this the primary way, or indeed the only way, of focusing by title, as it'd be prone to user error – it's unclear from the action name that it takes a regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants