Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard Shortcut - Launch a Google Search for Selected Text
#1
Lightbulb 
If you often have to google for selected text, this keyboard shortcut can help. Typically, after selecting the text (from anywhere), you have to copy it (to the clipboard), start your browser, go to google.com, paste it (from the clipboard) in the query field, and then click a button to launch the search. This whole process can be automated with the following AutoHotkey script:

Need help creating a keyboard shortcut with ShortKeeper using the following AutoHotkey code? This 5-minute tutorial will help!
ClipSaved := ClipboardAll
Clipboard =
SendInput, ^c
ClipWait, 2
if ErrorLevel 
{
  MsgBox % "Failed attempt to copy text to clipboard."
}
else
{
  TextSelected := Trim(Clipboard)
  StringReplace,TextSelected,TextSelected,`n,%A_SPACE%,A
  StringReplace,TextSelected,TextSelected,`r,,A
  StringReplace,TextSelected,TextSelected,%A_SPACE%,+,A
  Run % "https://www.google.com/search?q=%22" . TextSelected . "%22"
}
Clipboard := ClipSaved 

Spaces and tabs at the beginning and end of the selection will be omitted from the search.

This script will search for a phrase (instead of separate words). If you prefer to search for separate words, replace line #15 with:
Run % "https://www.google.com/search?q=" . TextSelected 
At line #15, you can specify your Google search country preference (e.g. google.ca for Canada, google.au for Australia, etc.).

This script will restore the previous clipboard content.

This script is optimized to be used with ShortKeeper. As such, there is no "Return" at the end and variable(s) don’t need to be cleared. ShortKeeper will do this automatically. Just copy/paste this code in the PARAM field in ShortKeeper, set your hotkey, save, and you’re ready to use your new keyboard shortcut.
Enterpad: For those who need more than a few shortcuts.

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)