Run Action based on URL Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lichtathlet
Posts: 6
Joined: 14 Oct 2019, 07:54

Run Action based on URL

14 Oct 2019, 08:01

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
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Run Action based on URL

14 Oct 2019, 08:17

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
Untested
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: Run Action based on URL  Topic is solved

14 Oct 2019, 08:20

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
Lichtathlet
Posts: 6
Joined: 14 Oct 2019, 07:54

Re: Run Action based on URL

14 Oct 2019, 09:29

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?
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Run Action based on URL

14 Oct 2019, 09:33

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
User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: Run Action based on URL

14 Oct 2019, 09:35

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: SimmoF, uchihito and 216 guests