Page 1 of 1

Search selected text in google (script)

Posted: 18 Aug 2021, 13:54
by a0l0e0x000
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.

Code: Select all

^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

Code: Select all

;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)

Re: Search selected text in google (script)

Posted: 02 Dec 2022, 06:14
by MedBooster

Code: Select all

;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
}


Re: Search selected text in google (script)

Posted: 17 Dec 2022, 22:13
by carno
MedBooster wrote:
02 Dec 2022, 06:14

Code: Select all

;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
}

This version runs very fast!

Re: Search selected text in google (script)

Posted: 09 Feb 2023, 10:53
by JSSatchell_
MedBooster wrote:
30 Nov 2022, 07:17
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.

If you're interested you can check it out here:
https://github.com/JSSatchell/HyperSearch

Here's a preview of the interface:
Image

Re: Search selected text in google (script)

Posted: 09 Feb 2023, 11:10
by MedBooster
JSSatchell_ wrote:
09 Feb 2023, 10:53
Looks good, thanks for the tip

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.

Re: Search selected text in google (script)

Posted: 09 Feb 2023, 11:32
by JSSatchell_
MedBooster wrote:
09 Feb 2023, 11:10
JSSatchell_ wrote:
09 Feb 2023, 10:53
Looks good, thanks for the tip

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.


Re: Search selected text in google (script)

Posted: 15 Oct 2023, 06:41
by MedBooster
JSSatchell_ wrote:
09 Feb 2023, 11:32
MedBooster wrote:
09 Feb 2023, 11:10
JSSatchell_ wrote:
09 Feb 2023, 10:53
Looks good, thanks for the tip

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.

Many settings, including shortcuts, can be changed by typing in commands in the search bar. You can find what settings can be changed in the documentation here: https://github.com/JSSatchell/HyperSearch#update-the-settings.

To edit the hotkeys, type Hotkey1/2> followed by your desired hotkey

Hotkey1 opens the GUI, Hotkey2 searches for highlighted text

For example: Set>Hotkey1>ctrl+space