Page 1 of 1

Code used to search google for a word or a URL as appropriate

Posted: Jan 12th, ’22, 12:35
by Elermino
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:

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
And this is the error:
https://imgur.com/a/ZMyow1h

Re: Code used to search google for a word or a URL as appropriate

Posted: Jan 17th, ’22, 09:49
by Marko
This is a warning, not an error. Probably you have added another script which includes a #Warn statement - remove it.

Alternatively you can add a

Code: Select all

text:=""
line just before a Loop, parse statement.

Re: Code used to search google for a word or a URL as appropriate

Posted: Jan 19th, ’22, 17:50
by Elermino
Marko wrote: Jan 17th, ’22, 09:49 This is a warning, not an error. Probably you have added another script which includes a #Warn statement - remove it.

Alternatively you can add a

Code: Select all

text:=""
line just before a Loop, parse statement.
Solved. Thanks

Re: Code used to search google for a word or a URL as appropriate

Posted: Jan 20th, ’22, 22:39
by Marko
Great, was it a #Warn statement?

Re: Code used to search google for a word or a URL as appropriate

Posted: Jan 25th, ’22, 14:52
by Elermino
Marko wrote: Jan 20th, ’22, 22:39 Great, was it a #Warn statement?
It seems to me that yes, since after clicking "ok" in the box that appeared, the order was already executed. Why is writing code different in FastKeys than writing an AutoHotkey script?

Re: Code used to search google for a word or a URL as appropriate

Posted: Jan 25th, ’22, 18:24
by Marko
There is no difference. The only thing is that other command codes may interfere.