#g::
GetText(Temp)
If NOT ERRORLEVEL
{
; Modify some characters that screw up the URL
; RFC 3986 section 2.2 Reserved Characters (January 2005): !*'();:@&=+$,/?#[]
StringReplace, Temp, Temp, `r`n, %A_Space%, All
StringReplace, Temp, Temp, #, `%23, All
StringReplace, Temp, Temp, &, `%26, All
StringReplace, Temp, Temp, +, `%2b, All
StringReplace, Temp, Temp, ", `%22, All
Run, msedge.exe -inprivate "https://www.google.com/search?q=%Temp%"
}
Return
GetText(ByRef MyText = "")
{
SavedClip := ClipboardAll ; Store full version of Clipboard
Clipboard = ; Empty the clipboard
Send ^c
ClipWait 0.5 ; Waits until the clipboard contains data with a timeout of 0.5 s
If ERRORLEVEL
{
Clipboard := SavedClip ; Restore Clipboard
MyText =
MsgBox, No text was sent to clipboard
Return
}
MyText := Clipboard
Sleep 10
Clipboard := SavedClip
Return MyText
}
Output:
#g::
{ ; V1toV2: Added bracket
GetText(Temp)
; Modify some characters that screw up the URL
; RFC 3986 section 2.2 Reserved Characters (January 2005): !*'();:@&=+$,/?#[]
Temp := StrReplace(Temp, "`r`n", A_Space)
Temp := StrReplace(Temp, "#", "`%23")
Temp := StrReplace(Temp, "&", "`%26")
Temp := StrReplace(Temp, "+", "`%2b")
Temp := StrReplace(Temp, "`"", "`%22")
Run("msedge.exe -inprivate `"https://www.google.com/search?q=" Temp "`"")
Return
} ; V1toV2: Added Bracket before function
GetText(&MyText := "")
{
SavedClip := ClipboardAll() ; Store full version of Clipboard
A_Clipboard := "" ; Empty the clipboard
Send("^c")
Errorlevel := !ClipWait(0.5) ; Waits until the clipboard contains data with a timeout of 0.5 s
If ERRORLEVEL
{
A_Clipboard := SavedClip ; Restore Clipboard
MyText := ""
MsgBox("No text was sent to clipboard")
Return
}
MyText := A_Clipboard
Sleep(10)
A_Clipboard := SavedClip
Return MyText
}
This gives the following error when the hotkey is pressed.
Error: This variable has not been assigned a value.
Specifically: local Temp
267: }
273: {
▶ 274: GetText(Temp)
277: Temp := StrReplace(Temp, "
", A_Space)
278: Temp := StrReplace(Temp, "#", "%23")
To fix this, GetText(Temp) should be replaced with Temp := GetText().
v1 code:
Output:
This gives the following error when the hotkey is pressed.
To fix this,
GetText(Temp)
should be replaced withTemp := GetText()
.