Code used to search google for a word or a URL as appropriate
Posted: Jan 12th, ’22, 12:35
This script is used to search Google as text if what is selected is a text and as a URL if what is selected is a URL, in my case this is activated by drawing a gesture. I have been told that the problem may be that the script requires variable initialization to work in FastKeys, but I don't know how to do that
This is the code:
And this is the error:
https://imgur.com/a/ZMyow1h
This is the code:
Code: Select all
port:=Clipboard
Send, ^c ;Ctrl C
Sleep, 100
Run, % (clip := Trim(clipboard)) ~= "^(https?://)?([\w\d]([\w\d]|(-[\w\d]))*\.)+\w+(/\S*)?$"
? (clip ~= "^(https?://|www\.)" ? "" : "http://") . clip
: "https://www.google.com/search?q=" . fix(clip)
Return
fix(url)
{
RegExMatch(url, "^(https?://)?(.+?)(/)?$", part)
Loop, Parse, part2
text .= A_LoopField ~= "[$&+,:;@""<>`%{}|\\^~[\] `]" ? Format("%{:X}", Asc(A_LoopField)) : A_LoopField
Return part1 text part3
}
Clipboard := port
https://imgur.com/a/ZMyow1h