Page 1 of 1
IfWinActive with Websites
Posted: 17 Jan 2020, 11:33
by Liaxim
Is it possible to look if a website is opened? I tried some IfWinActive things but I found only the browser class... like
would be nice if anyone have an idea
Re: IfWinActive with Websites
Posted: 17 Jan 2020, 14:11
by ufunk
Hi,
I am new here, so I am not sure if it helps, but I think something similar about this topic is written here:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=26947
Re: IfWinActive with Websites
Posted: 17 Jan 2020, 20:13
by telanx
An easy way is to match if a keyword exists in the title and then run the function you need.
Code: Select all
; keyword list, Case Sensitive
Keyword := "YouTube,Notion,Instagram"
!a::
WinGetTitle, Title, A ;Get Window Title
loop, Parse, Keyword, `, ;Keyword slicing
{
while inStr(Title, A_LoopField) { ;while keyword in title
switch A_LoopField { ;which keyword
case "Notion":
msgbox Notion
case "YouTube":
msgbox YouTube
case "Instagram":
msgbox ins
return
}
return
}
}
return
Re: IfWinActive with Websites
Posted: 12 Feb 2020, 14:38
by Liaxim
telanx wrote: ↑17 Jan 2020, 20:13
An easy way is to match if a keyword exists in the title and then run the function you need.
Code: Select all
; keyword list, Case Sensitive
Keyword := "YouTube,Notion,Instagram"
!a::
WinGetTitle, Title, A ;Get Window Title
loop, Parse, Keyword, `, ;Keyword slicing
{
while inStr(Title, A_LoopField) { ;while keyword in title
switch A_LoopField { ;which keyword
case "Notion":
msgbox Notion
case "YouTube":
msgbox YouTube
case "Instagram":
msgbox ins
return
}
return
}
}
return
Thanks for your answer.
I had a problem with the "switch A_LoopField". The program said me all the time that " A_LoopField" is not a recognized action.
I never used this command so did you @telanx or some one else know what is wrong there? Thanks in advance
Re: IfWinActive with Websites
Posted: 12 Feb 2020, 15:13
by gregster
Switch requires
AHK v1.1.31+.
Re: IfWinActive with Websites
Posted: 12 Feb 2020, 16:58
by Liaxim
Thx I used the Version v1.1.30 ^^ .
I tried it now but It just made nothing as the this code starts.
But now I have no errors anymore
Re: IfWinActive with Websites
Posted: 12 Feb 2020, 19:58
by boiler
Liaxim wrote: ↑12 Feb 2020, 16:58
I tried it now but It just made nothing as the this code starts.
You need to press
Alt +
A while the browser with the website in question is open to initiate the routine.
Re: IfWinActive with Websites
Posted: 13 Feb 2020, 13:28
by Liaxim
boiler wrote: ↑12 Feb 2020, 19:58
Liaxim wrote: ↑12 Feb 2020, 16:58
I tried it now but It just made nothing as the this code starts.
You need to press
Alt +
A while the browser with the website in question is open to initiate the routine.
I know ^^. I tried it but it just not work after the Keyword..
Re: IfWinActive with Websites
Posted: 13 Feb 2020, 13:50
by boiler
And you're sure the browser is the active window (and it's open to one of those sites) when you press Alt+A?
If you changed the code at all, even to different keywords, you might want to post your code because slight differences that don't seem important can cause issues when dealing with this stuff.
Re: IfWinActive with Websites
Posted: 13 Feb 2020, 14:28
by Liaxim
boiler wrote: ↑13 Feb 2020, 13:50
And you're sure the browser is the active window (and it's open to one of those sites) when you press Alt+A?
If you changed the code at all, even to different keywords, you might want to post your code because slight differences that don't seem important can cause issues when dealing with this stuff.
Thanks for you answer. Mhh I changed it a little bit but I think it was only the case options and the keyword I think. I try to make a automative login for the Protonmail login. ^^
Here is
Code: Select all
; my encrypted login data
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)
run https mail.protonmail.com /login Broken Link for safety
; I copied the title from the site but if it´s open it changed to a "Login | ProtonMail" ..
Keyword := "Login - ProtonMail"
!a::
WinGetTitle, Title, A ;Get Window Title
loop, Parse, Keyword, `, ;Keyword slicing
{
while inStr(Title, A_LoopField) { ;while keyword in title
switch A_LoopField { ;which keyword
case "Login - ProtonMail":
msgbox,, Login - ProtonMail
return
}
return
}
}
return
MsgBox,,found
Sleep, 5000
Click
send,{tab}
Sleep, 100
send %temporarybenutzer1%
Sleep, 500
send,{tab}
Sleep, 500
send %temporarypasswort1%
send {Enter}
Sleep, 500
Gosub, home
Return
Re: IfWinActive with Websites
Posted: 13 Feb 2020, 16:25
by boiler
(answered your PM)
Re: IfWinActive with Websites
Posted: 14 Feb 2020, 11:38
by Liaxim
This is the Version which I have right now. I made some Msgboxes to see where my failure is. The Script runs until the "msgbox,,while" and after it appears nothing more happens. Have anyone the answer to this problem?
Code: Select all
Gui, Destroy
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)
run https://mail.protonmail.com/login
Keyword := "Login - ProtonMail"
!a::
MsgBox,,begin
WinGetTitle, Title, A ;Get Window Title
loop, Parse, Keyword, `, ;Keyword slicing
{
MsgBox,,while ; This is the last outputed msgbox..
while inStr(Title, A_LoopField)
{ ;while keyword in title
MsgBox,,switch
switch A_LoopField
{ ;which keyword
case "Login - ProtonMail":
{
MsgBox,,found
Sleep, 5000
Click
send,{tab}
Sleep, 100
send %temporarybenutzer1%
Sleep, 500
send,{tab}
Sleep, 500
send %temporarypasswort1%
send {Enter}
Sleep, 500
gosub, home
}
return
}
return
}
return
}
return
Re: IfWinActive with Websites
Posted: 14 Feb 2020, 13:09
by boiler
You should MsgBox % Title "`n" A_LoopField in that spot so you can really see what’s happening.
Re: IfWinActive with Websites
Posted: 15 Feb 2020, 05:50
by Liaxim
boiler wrote: ↑14 Feb 2020, 13:09
You should
MsgBox % Title "`n" A_LoopField in that spot so you can really see what’s happening.
Thx for this tipp. I tried it now and as I see The Window showed me that "Login - ProtonMail" isn´t the right one because the window said "Login | ProtonMail - Mozilla Firefox". So the Browser name should be in there too.
I changed the Keyword now to "Login | ProtonMail - Mozilla Firefox" and as I see the msgbox both are the same but the case option isn´t working.. It loop everytime again. I tried some other case options too but nothing changed that.
Have anyone an idea what´s the failure?
Code: Select all
Gui, Destroy
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)
run https://mail.protonmail.com/login
Keyword := "Login | ProtonMail - Mozilla Firefox"
!a::
MsgBox,,begin
WinGetTitle, Title, A ;Get Window Title
loop, Parse, Keyword, `, ;Keyword slicing
{
MsgBox,,while
MsgBox % Title "`n" A_LoopField
while inStr(Title, A_LoopField)
MsgBox % Title "`n" A_LoopField
{ ;while keyword in title
MsgBox,,switch
switch A_LoopField
{ ;which keyword
case "Login | ProtonMail - Mozilla Firefox":
{
MsgBox,,found
Sleep, 5000
Click
send,{tab}
Sleep, 100
send %temporarybenutzer1%
Sleep, 500
send,{tab}
Sleep, 500
send %temporarypasswort1%
send {Enter}
Sleep, 500
}
return
}
return
}
return
}
return
}
Re: IfWinActive with Websites
Posted: 15 Feb 2020, 13:16
by boiler
You shouldn't have returns where you don't need them. That causes it to exit the subroutine instead of looping through. Also, you don't need the full title if you use
SetTitleMatchMode correctly. The code below works for me. Note that I got rid of extra returns and braces. Not sure why you had it waiting 5 seconds either, so I reduced that.
Code: Select all
SetTitleMatchMode, 1
Gui, Destroy
temporarybenutzer1 := b64Decode(protonbenutzer)
temporarypasswort1 := b64Decode(protonpasswort)
run https://mail.protonmail.com/login
Keyword := "Login | ProtonMail"
!a::
WinGetTitle, Title, A ;Get Window Title
loop, Parse, Keyword, `, ;Keyword slicing
{
while inStr(Title, A_LoopField)
{ ;while keyword in title
switch A_LoopField
{ ;which keyword
case "Login | ProtonMail":
Sleep, 500
Click
send,{tab}
Sleep, 100
send %temporarybenutzer1%
Sleep, 500
send,{tab}
Sleep, 500
send %temporarypasswort1%
send {Enter}
Sleep, 500
return
}
}
}
return