Search selected text in google (script)

Post your working scripts, libraries and tools for AHK v1.1 and older
a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Search selected text in google (script)

18 Aug 2021, 13:54

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
princegps
Posts: 2
Joined: 23 Jan 2016, 17:34

Re: Search selected text in google (script)

22 Oct 2022, 10:15

Thank you sooooo much.
This has made my life so easy.
Kudos!! 👍😊
MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: Search selected text in google (script)

30 Nov 2022, 06:18

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.]
MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: Search selected text in google (script)

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)
MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: Search selected text in google (script)

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
}

carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: Search selected text in google (script)

17 Dec 2022, 22:13

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!
JSSatchell_
Posts: 5
Joined: 29 Sep 2022, 21:41
Contact:

Re: Search selected text in google (script)

09 Feb 2023, 10:53

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
MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: Search selected text in google (script)

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.
JSSatchell_
Posts: 5
Joined: 29 Sep 2022, 21:41
Contact:

Re: Search selected text in google (script)

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.

MedBooster
Posts: 54
Joined: 24 Nov 2022, 12:33

Re: Search selected text in google (script)

15 Oct 2023, 06:41

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...
JSSatchell_
Posts: 5
Joined: 29 Sep 2022, 21:41
Contact:

Re: Search selected text in google (script)

16 Oct 2023, 09:38

@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

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 69 guests