Page 1 of 1
Google search tool - Help removing certain characters from clipboard.
Posted: 25 Apr 2022, 06:54
by Barnaby Ray
Hi everyone, I wondered if anyone can help me with a Google search tool I'm making to search for musical artists.
What I want to do, is select some text, then by using a hotkey it will perform a google search of the selected text inside quotation marks, followed by musical artist. So if I select Radiohead, the search will be "Radiohead" musical artist.
I've got it working for most searches, but if the band name includes an & symbol, the google search misses the & symbol and everything after it.. and if the band name also has quotation marks in it, ie DANIELA ALBARRAN "LA BRUJITA", the google search cuts off everything after the first quotation mark..
Is there a way to ignore the & symbol and quotation marks inside the clipboard?
Here is the script so far..
Code: Select all
^!m::
Clipboard := ""
send, ^c
ClipWait, 2
if ErrorLevel
{
MsgBox, The attempt to copy text onto the clipboard failed.
return
}
Clipboard=%Clipboard%
sleep, 200
Run chrome.exe "http://www.google.com/search?q=`%22%clipboard%`%22 musical artist"
sleep 200
return
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 25 Apr 2022, 07:08
by mikeyww
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 27 Apr 2022, 09:51
by Barnaby Ray
Thanks @mikeyww ... I will try to get my head around that
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 27 Apr 2022, 10:05
by mikeyww
It would just be a call to teadrinker's function. The function would return a string that has appropriately transformed the special characters (
&,
?, etc.) so that the URL still works. Of course, an alternative is to use
StrReplace to delete those symbols, but the function may be convenient.
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 27 Apr 2022, 10:56
by BoBo
Coincidentally I've stumbled over this API a day ago… probably worth a look?
http://api.chartlyrics.com/apiv1.asmx
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 28 Jun 2022, 11:50
by Barnaby Ray
@mikeyww
Hi, sorry it's been a while, I've been trying to figure this out for a while, but it's still not working.. wondered if you can tell me what I'm doing wrong?
I want to be able to highlight some text on a webpage, and when I run the script, it will copy the selected text, then perform a google search with the search term inside quotation marks, and followed by musical artist
So if the text is;
Ben & Holly
I want it to search for;
"Ben & Holly" musical artist
With my current script, I've tried to include the function you suggested, but I don't think I've put it in the right place? When I run it I still just get a search for;
"Ben
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
#Persistent
^F1::
Clipboard := ""
winactivate, ahk_exe chrome.exe
sleep, 50
send, ^c
ClipWait, 2
if ErrorLevel
{
MsgBox, The attempt to copy text onto the clipboard failed.
return
}
Clipboard=%Clipboard%
sleep, 200
str := Clipboard
decoded := EncodeDecodeURI(str, false)
sleep 200
MsgBox, % decoded
Run chrome.exe "http://www.google.com/search?q=`%22%decoded%`%22 musical artist"
sleep 200
return
EncodeDecodeURI(str, encode := true, component := true) {
static Doc, JS
if !Doc {
Doc := ComObjCreate("htmlfile")
Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
JS := Doc.parentWindow
( Doc.documentMode < 9 && JS.execScript() )
}
Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}
ESC::ExitApp
Re: Google search tool - Help removing certain characters from clipboard. Topic is solved
Posted: 28 Jun 2022, 12:21
by mikeyww
Code: Select all
^F1::
Clipboard =
Send ^c
ClipWait, 0
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else Run, % "chrome.exe http://www.google.com/search?q=" EncodeDecodeURI(Trim(Clipboard))
Return
EncodeDecodeURI(str, encode := true, component := true) {
Static Doc, JS
If !Doc
Doc := ComObjCreate("htmlfile"), Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
, JS := Doc.parentWindow , (Doc.documentMode < 9 && JS.execScript())
Return JS[(encode ? "en" : "de") "codeURI" (component ? "Component" : "")](str)
}
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 28 Jun 2022, 13:14
by flyingDman
Perhaps:
Code: Select all
var = A&B musical artist
Run % "chrome.exe ""http://www.google.com/search?q=" strreplace(var,"&","`%26") ""
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 28 Jun 2022, 14:04
by mikeyww
Certainly; and can add "musical artist" or whatever as noted, to the search string. The encoder handles various types of punctuation, spaces, etc. that may also require special handling.
Re: Google search tool - Help removing certain characters from clipboard.
Posted: 29 Jun 2022, 05:10
by Barnaby Ray
Amazing, thank you so much!