hey guys,
I'm struggling with an action. Basically what I'm trying to achieve is to run actions based on a url.
So for example
::!m::
#IfWinActive ahk_exe firefox.exe
send ^l ; select url
send ^c ; copy url
if URL contains = "?mobile_view" {
action
}
else {
action 2
}
can anyone help me out?
thanks in advance
Run Action based on URL Topic is solved
-
- Posts: 6
- Joined: 14 Oct 2019, 07:54
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: Run Action based on URL
Code: Select all
::!m::
#IfWinActive ahk_exe firefox.exe
send ^l ; select url
send ^c ; copy url
if (InStr(clipboard, "?mobile_view")) {
;action
}
else {
;action 2
}
return
Re: Run Action based on URL Topic is solved
Looks like you want a hotkey instead of a hotstring. And the #IfWinActive directive goes before it, not after. Use InStr to see if the URL contains that string.
Code: Select all
#IfWinActive ahk_exe firefox.exe
!m::
send ^l ; select url
send ^c ; copy url
if InStr(Clipboard, "?mobile_view") {
action
}
else {
action 2
}
return
-
- Posts: 6
- Joined: 14 Oct 2019, 07:54
Re: Run Action based on URL
Thank you very much. That worked for me.
Out of curiosity, when using InStr(Clipboard) is there also a way to alter the url or stripping parts of it easily?
Out of curiosity, when using InStr(Clipboard) is there also a way to alter the url or stripping parts of it easily?
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: Run Action based on URL
You can split on different characters or use regex. Since it seems like you are using arguments in the url you can split it by the ? first, then by & for each variable input and finally split by = to get the variable name and the value. If you are only interested in one part of the url string I recommend using regex as that is a bit easier
Re: Run Action based on URL
You can't alter the contents of a variable using InStr, but you can with SubStr, RegExReplace, and many other ways. That applies to the Clipboard variable as well.