WinTitle - fine-tuning the target

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
StefOnSteroids
Posts: 77
Joined: 08 Aug 2015, 10:22

WinTitle - fine-tuning the target

19 Jun 2018, 00:47

I managed to bring up my own right mouse menu in Thunderbird:

Code: Select all

#If WinActive ("ahk_exe thunderbird.exe")
RButton::Menu, MyTBird, Show
But I don't want this menu to come up when I am composing a mail. In certain dialogs - when WinTitle contains the words "Address Book" or "Write" I want to revert to the default Thunderbird context menu.

I have tried all kinds of WinActive and WinNotActive, with and without #-directives, in nested conditionals with parentheses and quotes and what not - but I just can't get it to work. Could someone help me out, please?
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinTitle - fine-tuning the target

19 Jun 2018, 01:11

Hallo,
try:

Code: Select all

SetTitleMatchMode, 2 ;A window's title can contain WinTitle anywhere inside
GroupAdd, Thunderbird2, Address Book ahk_exe thunderbird.exe
GroupAdd, Thunderbird2, Write ahk_exe thunderbird.exe
Return
#If WinActive("ahk_group Thunderbird2") ;(specific) before general
RButton::ToolTip, ahk_group Thunderbird2
#If WinActive("ahk_exe thunderbird.exe") ;(general)
RButton::ToolTip, ahk_exe thunderbird.exe
#If
Last edited by Rohwedder on 19 Jun 2018, 01:25, edited 1 time in total.
gregster
Posts: 9012
Joined: 30 Sep 2013, 06:48

Re: WinTitle - fine-tuning the target

19 Jun 2018, 01:14

Rohwedder should have you covered. But note that between a function name and its parentheses with the parameters, there is no space allowed (there is one in your original post).
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: WinTitle - fine-tuning the target

19 Jun 2018, 01:21

Try this:

Code: Select all

#If WinActive("ahk_exe thunderbird.exe")
And Not WinActive("Address Book")
And Not WinActive("Write")
RButton::Menu, MyTBird, Show
I hope that helps.untested
StefOnSteroids
Posts: 77
Joined: 08 Aug 2015, 10:22

Re: WinTitle - fine-tuning the target

19 Jun 2018, 02:28

@Rohwedder and gregster
Whoa, your approach is totally different from anything I could have ever dreamed up. :shock:
And it works! Hurrah!
Many thanks, also to gregster for pointing out my syntax error.

@wolf_II
Your solution works nicely, too. :D And it's close to one of my attempted routes.
Could someone please spot my syntax error, I'd like to learn from my mistakes:

Code: Select all

#If WinActive("ahk_exe thunderbird.exe") and not WinActive("Write" or "Address")
#If WinActive("ahk_exe thunderbird.exe") and (!WinActive("Write" or "Address"))
May I ask what's wrong - in general logic or syntax-wise - using the ExcludeText parameter:

Code: Select all

WinActive(WinTitle , WinText, ExcludeTitle, ExcludeText)
WinActive("ahk_exe thunderbird.exe", , "Write")
WinActive("ahk_exe thunderbird.exe", , ("Write" or "Address"))
Using ExcludeText - is that the wrong track to start with, or is it just a matter of getting the syntax right?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: WinTitle - fine-tuning the target

19 Jun 2018, 02:33

"Write" or "Address" this results in a boolean (True). WinActive(True) is not what you want.

WinActive(x) or WinActive(y) is what you want instead.
Using ExcludeText - is that the wrong track to start with, or is it just a matter of getting the syntax right?
wrong track, given info in OP. OP talks about WinTitles.
And it's close to one of my attempted routes.
That's what I aimed for. If possible, use plain English to describe what we want. Translate to AHK. Your post was very inviting to do so.
I count this as self-documenting code.
StefOnSteroids
Posts: 77
Joined: 08 Aug 2015, 10:22

Re: WinTitle - fine-tuning the target

19 Jun 2018, 03:26

Thank you wolf_II,
I really appreciate your feedback, it's helping me tremendously.
wolf_II wrote:"Write" or "Address" this results in a boolean (True). WinActive(True) is not what you want.
I see what you're saying. By adopting ahk-help snippets to my scenario I ended up with twisted logic. It's not so much the syntax, it's the resulting logic that's at fault.

ExcludeText was a misnomer, ExcludeTitle was what I wanted to say. Regardless, it also slips up because of the boolean logic you pointed out, I can see that now.

Many thanks. :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, mebelantikjaya and 330 guests