wetin
wetin

Reputation: 438

AHK WinActivate not able to exclude

I just want to exclude Google Chrome in a WinActivate. I've tried everything from fully qualifying the title of the window to using variables, strings, none of this works. It always switches to chrome because I have two windows open that match the string string -- Chrome and Windows Explorer. I want to switch to windows explorer.

Ticket_Out := "00123456"
xclude:= Ticket_Out . "00123456 | Salesforce - Google Chrome"

WinActivate % Ticket_Out,, xclude, ; doesn't work
WinActivate, "00123456",, "00123456 | Salesforce - Google Chrome", ; also doesn't work

I know there is a WinActivateBottom but I really want to avoid using this. I really just would like the exclude to work. What's wrong with my syntax or my command?

Upvotes: 0

Views: 679

Answers (1)

0x464e
0x464e

Reputation: 6489

Every parameter in any command (unless otherwise specified) uses legacy syntax.

WinActivate % Ticket_Out,, xclude,
WinActivate, "00123456",, "00123456 | Salesforce - Google Chrome",

In the first one you force an expression in the first parameter correctly by starting the parameter off with a % followed up by a space. But then in the 3rd parameter you're in legacy syntax again and are just typing in xclude. This is going to be interpreted as literal text, and not a variable. Start that parameter also off with a % and a space.

And in the second one you're again not evaluating an expression on either of the parameters, so they're both interpreted as literal text. Including the quotes. In legacy syntax you don't quote strings since everything is already literal text by default.

WinActivate, % Ticket_Out, , % xclude 
WinActivate, % "00123456", , % "00123456 | Salesforce - Google Chrome"

Also removed the trailing commas you had. They don't belong there.
And now it should work, assuming the window titles and your title match mode are in order.


Alternatively to using the exclude parameter, you could be more specific when specifying the window title.
For example you could make use of ahk_exe like this:

WinActivate, % "Title Of My Window ahk_exe chrome.exe"

And now you only match windows which come from a process named chrome.exe.


Overall, your trouble came mostly from not knowing the difference between legacy syntax and the modern expression syntax.
Here's a good documentation page to get you started on the differences:
https://www.autohotkey.com/docs/Language.htm

Upvotes: 1

Related Questions