Script will search selected text in your default browser using google search. If you selected an "https://" link it will send you directly to the site rather than searching the link in google.
^Numpad1:: ; change to preferred hotkey
clip := clipboard
send, ^c
url := "https://www.google.com/search?q="
is_it_an_url := SubStr(clipboard, 1 , 8)
if (is_it_an_url = "https://") { ; if it starts with "https://" go to, rather than search in google search
run, %clipboard%
}
else { ;search using google search
joined_url = %url%%clipboard%
run, %joined_url%
}
clipboard := clip ;put the last copied thing back in the clipboard
return
Re: Search selected text in google (script)
Posted: 22 Oct 2022, 10:15
by princegps
Thank you sooooo much.
This has made my life so easy.
Kudos!!
Re: Search selected text in google (script)
Posted: 30 Nov 2022, 06:18
by MedBooster
This is great!
An important question;
Maybe anyone would be able to make it search for highlighted text? Meaning that you would not have to copy it, simply select/highlight it with your cursor.
I tweaked it a bit to be used with Win+W (luckily it overrides the Windows 10 shortcut)
I also added Win+Shift+W for searching with DuckDuckGo
;reference https://www.autohotkey.com/boards/viewtopic.php?t=93891 a0l0e0x000
;Google
#w:: ; change to preferred hotkey
clip := clipboard
send, ^c
url := "https://www.google.com/search?q="
is_it_an_url := SubStr(clipboard, 1 , 8)
if (is_it_an_url = "https://") { ; if it starts with "https://" go to, rather than search in google search
run, %clipboard%
}
else { ;search using google search
joined_url = %url%%clipboard%
run, %joined_url%
}
clipboard := clip ;put the last copied thing back in the clipboard
return
;DuckDuckGo
#+w:: ; change to preferred hotkey
clip := clipboard
send, ^c
url := "https://duckduckgo.com/?q="
is_it_an_url := SubStr(clipboard, 1 , 8)
if (is_it_an_url = "https://") { ; if it starts with "https://" go to, rather than search in google search
run, %clipboard%
}
else { ;search using google search
joined_url = %url%%clipboard%
run, %joined_url%
}
clipboard := clip ;put the last copied thing back in the clipboard
return
[Mod edit: Replaced quote tags with [code][/code] tags.]
Re: Search selected text in google (script)
Posted: 30 Nov 2022, 07:17
by MedBooster
another improvement to the script could be to make it automatically switch to your main Browser.
Any ideas on how to do that? As of now you have to switch manually (if the browser is under the program you're in, like Anki for example)
;Some improvements with the help of andreas@ESA:~$ sudo -i
#w::searchOrVisitFromClip("https://www.google.com/search?q=")
#+w::searchOrVisitFromClip("https://duckduckgo.com/?q=")
searchOrVisitFromClip(searchUrl){
clip := clipboardAll
clip := ""
send, ^c
ClipWait, 0.5
if(ErrorLevel){
} else if (clipboard ~= "^https?:\/\/") { ; if clipboard content is an http or https protocol url
run, % clipboard
} else { ;search using the provided url
run, % searchUrl clipboard
}
clipboard := clip ;put the last copied thing back in the clipboard
}
;Some improvements with the help of andreas@ESA:~$ sudo -i
#w::searchOrVisitFromClip("https://www.google.com/search?q=")
#+w::searchOrVisitFromClip("https://duckduckgo.com/?q=")
searchOrVisitFromClip(searchUrl){
clip := clipboardAll
clip := ""
send, ^c
ClipWait, 0.5
if(ErrorLevel){
} else if (clipboard ~= "^https?:\/\/") { ; if clipboard content is an http or https protocol url
run, % clipboard
} else { ;search using the provided url
run, % searchUrl clipboard
}
clipboard := clip ;put the last copied thing back in the clipboard
}
another improvement to the script could be to make it automatically switch to your main Browser.
Any ideas on how to do that? As of now you have to switch manually (if the browser is under the program you're in, like Anki for example)
I have been working on a script that searches any highlighted text, provides a search bar for the internet, and stores saved hyperlinks. It will also use your default browser automatically, currently it can switch between Edge, Chome, Firefox, and Brave.
Do you have an explanatory (e.g. on YouTube/Rumble?) video explaining it? Just from my impression of the screenshot it seems a little complicated.
Yep! Here's a quick start guide that will show you the basics and how to get it set up with Chrome bookmarks.
Hello again, I've been trying out the program, and I was wondering if you are supposed to be able to move the Window around (for me it stays where it is opened, maybe it is DisplayFusion interfering with the program.
Also, it would have been nice if you were able to right click on the tray icon to change shortcuts etc...
Re: Search selected text in google (script)
Posted: 16 Oct 2023, 09:38
by JSSatchell_
@MedBooster
By default the UI will open centered on the current mouse position. To change the location you can simply move the mouse and press the shortcut hotkey again and it will reopen there.