Author Topic: Focus/Show window when an application's window title constantly changes?  (Read 1037 times)

wangchobo

  • Newbie
  • *
  • Posts: 1
Hello,

I want to be able to switch between applications, basically alt-tabbing but to a specific window of my choosing.

But the problem is that when I display window as Spotify or Opera, or any other software that has its window title change, the command breaks.


So this is what I have right now:
When I say, [focus;bring up] [spotify;opera]

Code: [Select]
Set text [focus] to '{TXTREPLACE:focus:focus:}' (Trim)
Set text [focus] to '{TXTREPLACE:focus:bring up:}' (Trim)
Begin Text Compare : [focus] Equals 'spotify'
    Display window 'Spotify' As [Maximize]
    Display window 'Spotify' As [Show]
Else If Text Compare : [opera] Equals 'wave link'
    Display window 'Opera' As [Normal]
    Display window 'Opera' As [Show]

Spotify's current playing song is displayed as the window's title and the same thing with Opera's current tab.

Is there any way to focus an application instead of the title itself?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Focus/Show window when an application's window title constantly changes?
« Reply #1 on: November 20, 2022, 08:07:28 PM »
As mentioned in the documentation, and the tooltip for the "Window Title" field of the "Perform a Window Function" action, there are four methods to try and target a window: by title, by process name, by process ID, or by class.

Wildcards are also accepted, to match part of E.G. a window title.


Are none of those options applicable to your command?
Web browsers and browser-based (E.G. Spotify, which runs in Electron, a Chromium-based web browser) applications can be difficult to target due to their multi-process nature, however there may be a combination of options that works for your use case.



As something of a side note, your command shouldn't work correctly regardless in the form you have posted, as you're not getting the value of the spoken command, so the value of "focus" would be "Not set", unless you've set it in another command.

In addition to that, unless you intend to use the value of "focus" in another command, using a variable is not required.
Instead you can use either the "Contains" or "Ends With" operator for your condition combined with the "{CMD}" token, or continue to use the "Equals" operator but with the "{CMDSEGMENT:}" token to get only the contents of the dynamic command section where you're specifying the application name.

Lastly, if you do require replacing text, rather than using the deprecated and undocumented "{TXTREPLACE:}" token, you could use the "Set a Text Value" action's built-in "Replace with" option.


Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, which contains information on VoiceAttack's features.

These topics may also be of use, in addition to the official documentation:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up
{CMDSEGMENT:} token behavior