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

Discussion, questions and support.
Post Reply
Elermino
Posts: 11
Joined: Nov 12th, ’21, 19:20

Post by Elermino » 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:

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
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » 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.
Elermino
Posts: 11
Joined: Nov 12th, ’21, 19:20

Post by Elermino » Jan 19th, ’22, 17:50

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
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jan 20th, ’22, 22:39

Great, was it a #Warn statement?
Elermino
Posts: 11
Joined: Nov 12th, ’21, 19:20

Post by Elermino » Jan 25th, ’22, 14:52

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?
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jan 25th, ’22, 18:24

There is no difference. The only thing is that other command codes may interfere.
Post Reply