Edit Chrome URL by searching and replacing key phrases, copy it, open a new tab paste the edited URL Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rae
Posts: 5
Joined: 18 Jun 2018, 15:24

Edit Chrome URL by searching and replacing key phrases, copy it, open a new tab paste the edited URL

19 Jun 2018, 09:55

Hi All,

I'm a complete noob at this, but I'm trying to do something I don't even know how to get started with.

I want to take my current browser URL, look for the words 'create', view' and 'edit', and replace it with something else.
Then I'd like for this edited URL to open in a new tab.

I can conceptualize putting in the commands for it, something along the lines of:

Code: Select all

^!+F1::
^+L (to select the URL)
{do the finding and editing and copying}
^+T (to open a new tab)
^+L (to select the URL field)
^+V (to copy edited text into URL field)
Return
I just dont know how to get started to look for the key words and then replacing them.
Any help is appreciated!
rae
Posts: 5
Joined: 18 Jun 2018, 15:24

Re: Edit Chrome URL by searching and replacing key phrases, copy it, open a new tab paste the edited URL

27 Oct 2019, 01:29

I was able to finally do this after finding a very helpful link here:
- https://www.autohotkey.com/boards/viewtopic.php?t=3702

This code was outputting the browser URL to a MsgBox. I changed that bit to make it copy to a variable on which I later used RegExReplace() to do my modifications.

Here's a brief summary of the part of the code I changed If anyone comes across this at a later point in time and find that they need something similar, they should be able to compare this code and code from the link above to see the difference. Hopefully it'll be of help!

Code: Select all

^+!u::
	nTime := A_TickCount
	sURL := GetActiveBrowserURL()
	WinGetClass, sClass, A
	If (sURL != "")
		sURL2 := sURL
	Else If sClass In % ModernBrowsers "," LegacyBrowsers
		MsgBox, % "The URL couldn't be determined (" sClass ")"
	Else
		MsgBox, % "Not a browser or browser not supported (" sClass ")"
	If InStr(sURL2, "View") ;just to make sure that i do the regexreplace if the url contains the specific string i want to replace
		sURL3 := RegExReplace(sURL2, "/View/", "/ReplacementText/")
	Else If InStr(sURL2, "Edit") ;just to make sure that i do the regexreplace if the url contains the specific string i want to replace
		sURL3 := RegExReplace(sURL2, "/Edit/", "/ReplacementText/")
	Else
		sURL3 := RegExReplace(sURL2, "/Create", "/ReplacementText")
	clipboard := sURL3
	Send ^t
	Send ^l
	Send ^v
	Send {Enter}
	Return
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Edit Chrome URL by searching and replacing key phrases, copy it, open a new tab paste the edited URL  Topic is solved

27 Oct 2019, 01:34

rae wrote:
27 Oct 2019, 01:29
I was able to finally do this after finding a very helpful link here:
- https://www.autohotkey.com/boards/viewtopic.php?t=3702

This code was outputting the browser URL to a MsgBox. I changed that bit to make it copy to a variable on which I later used RegExReplace() to do my modifications.

Here's a brief summary of the part of the code I changed If anyone comes across this at a later point in time and find that they need something similar, they should be able to compare this code and code from the link above to see the difference. Hopefully it'll be of help!

Code: Select all

^+!u::
	nTime := A_TickCount
	sURL := GetActiveBrowserURL()
	WinGetClass, sClass, A
	If (sURL != "")
		sURL2 := sURL
	Else If sClass In % ModernBrowsers "," LegacyBrowsers
		MsgBox, % "The URL couldn't be determined (" sClass ")"
	Else
		MsgBox, % "Not a browser or browser not supported (" sClass ")"
	If InStr(sURL2, "View") ;just to make sure that i do the regexreplace if the url contains the specific string i want to replace
		sURL3 := RegExReplace(sURL2, "/View/", "/ReplacementText/")
	Else If InStr(sURL2, "Edit") ;just to make sure that i do the regexreplace if the url contains the specific string i want to replace
		sURL3 := RegExReplace(sURL2, "/Edit/", "/ReplacementText/")
	Else
		sURL3 := RegExReplace(sURL2, "/Create", "/ReplacementText")
	clipboard := sURL3
	Send ^t
	Send ^l
	Send ^v
	Send {Enter}
	Return
Instead of

Code: Select all

clipboard := sURL3
	Send ^t
	Send ^l
	Send ^v
	Send {Enter}
	Return
did you try

Code: Select all

run, % sURL3
Return
That should automatically open a new tab with the URL in whatever your default browser is

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Billykid and 147 guests