AutoHotkey script to search Google for selection, or open URL (from any program) Auteur du fil: Michael Beijer
| Michael Beijer Royaume-Uni Local time: 11:36 Membre (2009) néerlandais vers anglais + ...
Ever wanted to be able to just select some text and click a shortcut to launch a Google search in a browser? If so, you might enjoy this AutoHotkey script. It works anywhere, that is, you can just select a word or phrase in your CAT tool, in Word, ... anywhere. ;-----------------------------------------------------------*** ;### Search Google for selection, or open URL ### browser="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ... See more Ever wanted to be able to just select some text and click a shortcut to launch a Google search in a browser? If so, you might enjoy this AutoHotkey script. It works anywhere, that is, you can just select a word or phrase in your CAT tool, in Word, ... anywhere. ;-----------------------------------------------------------*** ;### Search Google for selection, or open URL ### browser="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" #g:: ;Copy Clipboard to prevClipboard variable, clear Clipboard. prevClipboard := ClipboardAll Clipboard = ;Copy current selection, continue if no errors. SendInput, ^c ClipWait, 2 if !(ErrorLevel) { ;Convert Clipboard to text, auto-trim leading and trailing spaces and tabs. Clipboard = %Clipboard% ;Clean Clipboard: change carriage returns to spaces, change >=1 consecutive spaces to + Clipboard := RegExReplace(RegExReplace(Clipboard, "\r?\n"," "), "\s+","+") ;Open URLs, Google non-URLs. URLs contain . but do not contain + or .. or @ if Clipboard contains +,..,@ Run, %browser% www.google.co.uk/search?q=%Clipboard% else if Clipboard not contains . Run, %browser% www.google.co.uk/search?q=%Clipboard% else Run, %browser% %Clipboard% } ;Restore Clipboard, clear prevClipboard variable. Clipboard := prevClipboard prevClipboard = return ;-----------------------------------------------------------*** Michael
[Edited at 2014-06-14 08:11 GMT] ▲ Collapse | | | Very useful script, Michael, thank you! | Jun 14, 2014 |
Very useful script Michael, thank you! If I may make a suggestion for other users: Michael's script could be personalized to better answer your needs. For example, Run, %browser% www.google.co.uk/search?q=%Clipboard% Could be changed to use your local version of Google, for example: ... See more Very useful script Michael, thank you! If I may make a suggestion for other users: Michael's script could be personalized to better answer your needs. For example, Run, %browser% www.google.co.uk/search?q=%Clipboard% Could be changed to use your local version of Google, for example: Run, %browser% www.google.it/search?q=%Clipboard% for Italian, or even more complex searches, like: Run, %browser% www.google.it/search?as_q=%Clipboard%&lr=lang_it&cr=countryIT To search the Italian version of Google for pages in Italian coming from Italy. ▲ Collapse | | | Michael Beijer Royaume-Uni Local time: 11:36 Membre (2009) néerlandais vers anglais + ... AUTEUR DU FIL Thanks for the suggestion Riccardo! | Jun 14, 2014 |
I should also have mentioned that you can of course change the shortcut used to trigger it. I currently have this set to: Windows key + G. Here are a few useful things to know when writing AHL scripts, and which might help you to read this one: ! = Alt ^ = Control # = windows + = shift ClipWait = pauses the script for a specified time, to make it work better I didn't write this myself, I found it on... See more I should also have mentioned that you can of course change the shortcut used to trigger it. I currently have this set to: Windows key + G. Here are a few useful things to know when writing AHL scripts, and which might help you to read this one: ! = Alt ^ = Control # = windows + = shift ClipWait = pauses the script for a specified time, to make it work better I didn't write this myself, I found it on the AHK forum, where I find many of the useful scripts I use in my daily work. This particular one is from here: http://www.autohotkey.com/board/topic/13404-google-search-on-highlighted-text/ Incidentally, I am working on a new website where I will collect a bunch of useful AHK scripts that might come in handy to translators. Stay tuned! Michael ▲ Collapse | | | Emma Goldsmith Espagne Local time: 12:36 Membre (2004) espagnol vers anglais Reinventing the wheel? | Jun 14, 2014 |
I use IntelliWebSearch to do this. It's based on AutoHotKey scripts too, so you can set up searches in Google itself, directly access other websites, or even local dictionary resources, all by selecting a single word and using a shortcut. It has a nice interface for those of us who are put off by complex-looking scripts. You obviously don't fall into this category, Michael! One of the reasons I particularly like IWS is that, as you say, you can launch a search from any... See more I use IntelliWebSearch to do this. It's based on AutoHotKey scripts too, so you can set up searches in Google itself, directly access other websites, or even local dictionary resources, all by selecting a single word and using a shortcut. It has a nice interface for those of us who are put off by complex-looking scripts. You obviously don't fall into this category, Michael! One of the reasons I particularly like IWS is that, as you say, you can launch a search from any Windows application. Other tools do this - memoQ, XBench and Studio (through plug-ins) - but I prefer to have a method that works across all applications. So IntelliWebSearch or your AutoHotKey script are much more flexible. ▲ Collapse | |
|
|
Michael Beijer Royaume-Uni Local time: 11:36 Membre (2009) néerlandais vers anglais + ... AUTEUR DU FIL a bunch of possibly useful AHK scripts | Jun 14, 2014 |
Emma Goldsmith wrote: I use IntelliWebSearch to do this. It's based on AutoHotKey scripts too, so you can set up searches in Google itself, directly access other websites, or even local dictionary resources, all by selecting a single word and using a shortcut. It has a nice interface for those of us who are put off by complex-looking scripts. You obviously don't fall into this category, Michael! One of the reasons I particularly like IWS is that, as you say, you can launch a search from any Windows application. Other tools do this - memoQ, XBench and Studio (through plug-ins) - but I prefer to have a method that works across all applications. So IntelliWebSearch or your AutoHotKey script are much more flexible. Hi Emma, Good point. And, yes, I too use IWS. However, I like to keep as many of my ‘translation workflow solutions’ in one place as possible: I have a single AHK script that auto-starts when I boot up my computer that contains all kinds of useful little scripts. E.g.: ;--------------------------------------------------* ; surrounds selection with double, straight quotes: "text" ; useful for Google searches ^+2:: Send ^c Sleep 100 clipboard = "%clipboard%" Send ^v return ;-----------------------------------------------------------*** ; surrounds selection with single, curly quotes: ‘text’ ^+':: Send ^c Sleep 100 clipboard = ‘%clipboard%’ Send ^v return ;-----------------------------------------------------------*** ; shortcut to print date in the following format: 2014-06-14 ^+F4:: Send %A_YYYY%-%A_MM%-%A_DD% return ;-----------------------------------------------------------*** ; deletes selection and moves cursor one space to the left (useful in CAT tools) ; ^+d:: ; Send, {Del}{Space}{Left} ; return ;-----------------------------------------------------------*** ; Ctrl+Shift+comma moves cursor one space to the left (useful in CAT tools) ^+,:: Send, {Space}{Left} return ;-----------------------------------------------------------*** ; move your caret to a misspelled word that is underlined and click this to automatically select the correct spelling (it does the following: moves mouse pointer to caret, right-clicks, clicks down, once, and enters) usually, the first option down is the correct one. (this script is volatile; may need some work to get working) #IfWinActive, CafeTran #Persistent CoordMode, Caret, Screen ^+#:: ; Ctrl+Shift # MovePosX:=A_CaretX +550 ; Adjust 5 pixels to the right of A_CaretX position MovePosY:=A_CaretY -10 ; Adjust 10 Pixels above A_CaretY position MouseMove, %MovePosX% , %MovePosY% SendInput {Click,Right} Send, {Down}{Enter} Return ;-----------------------------------------------------------*** ; Some special symbols ;^+3::Send, {U+00A3} ; Pound symbol ( £ ) ; ^+2::Send, {U+20AC} ; Euro symbol ( € ) ^+-::Send, {U+2014} ; Em dash symbol ( — ) ^+6::Send, {U+2013} ; En dash symbol ( – ) ;^+::Send, {U+2212} ; Minus sign ( − ) ^+3::Send, {U+0022}{U+0022} ; QUOTATION MARK ( " " ) ^+o::Send, {U+2022} ; Bullet point ( • ) ^+9::Send, {U+2018} ; Single, curly, opening quotation mark ( ‘ ) ^+0::Send, {U+2019} ; RIGHT SINGLE QUOTATION MARK ( ’ ) ; messes up Hunspell ;^+0::Send, {U+02BC} ; MODIFIER LETTER APOSTROPHE ( ʼ ) ; works with Hunspell ^+[::Send, {U+201C} ; Double, curly, opening quotation mark ( “ ) ^+]::Send, {U+201D} ; Double, curly, closing quotation mark ( “ ) ; ^+,::Send, {U+275D} ; Double, curly, dingbat opening quotation mark ( ❝ ) ; ^+.::Send, {U+275E} ; Double, curly, dingbat closing quotation mark ( ❞ ) ^+x::Send, {U+00D7} ; Multiplication symbol ( × ) ^+e::Send, {U+2026} ; ellipsis (…) ^+`::Send, {U+00A9} ^Space::Send, {U+200B} ; invisible spaces ('ZERO WIDTH SPACE') (often used to secretly mark text for later identification) ;-----------------------------------------------------------*** ; mouselessly insert highlighted term from source window in memoQ ; script to automatically move your mouse pointer to the caret so you can double-click on a highlighted term in the source segment in order to insert it WITHOUT USING YOUR MOUSE. before clicking: hit Tab (to change the focus to the src segment), and then use the arrow keys to place the caret in/on the desired word. ; with a little help from Robert Ilbrink: http://superuser.com/questions/591697/move-mouse-pointer-to-caret-with-shortcut-in-win8 #IfWinActive, memoQ #Persistent CoordMode, Caret, Screen ^+i:: ; Ctrl+Shift+/ MovePosX:=A_CaretX +5 ; Adjust 5 pixels to the right of A_CaretX position MovePosY:=A_CaretY -10 ; Adjust 10 Pixels above A_CaretY position MouseMove, %MovePosX% , %MovePosY% Click 2 ;double-click Return ;-----------------------------------------------------------*** ; Map F13 to Print screen F13::PrintScreen ;-----------------------------------------------------------*** etc.! Michael | | | 2nl (X) Pays-Bas Local time: 12:36 Solution for OS X | Jun 15, 2014 |
In native OS X apps you can press the right mouse button and select "Search with Google". Some tools offer a way to add Google searches (e.g. CafeTran does). In other apps you can add your own search feature with Keyboard Maestro and other automation tools. If anyone is interested: I can post an example here: http://www.proz.com/forum/apple_mac_operating_systems-68.html | | | neilmac Espagne Local time: 12:36 espagnol vers anglais + ... Explanation for dummies, please. | Jun 17, 2014 |
Riccardo Schiaffino wrote: Very useful script Michael, thank you! If I may make a suggestion for other users: Michael's script could be personalized to better answer your needs. For example, Run, %browser% www.google.co.uk/search?q=%Clipboard% Could be changed to use your local version of Google, for example: Run, %browser% www.google.it/search?q=%Clipboard% for Italian, ... I'm interested in this function (to get Google results in English rather than my local Spanish, which it tends to default to), but have no experience or more than a vague idea of how to set it up. I'd need a detailed explanation of how to do so, step by step. From the start. | | |
|
|
Silviu Lungu Roumanie Local time: 13:36 anglais vers roumain
Is there a way to use the code with autohotkey version 2? Thank you! | | | Michael Beijer Royaume-Uni Local time: 11:36 Membre (2009) néerlandais vers anglais + ... AUTEUR DU FIL
Silviu Lungu wrote: Is there a way to use the code with autohotkey version 2? Thank you! ^/::GoogleSearch() ; Ctrl+/ triggers GoogleSearch UriEncode(Uri) { Uri := StrReplace(Uri, " ", "%20") ; Replace spaces with '%20' ; Add other characters you want to replace here, if necessary return Uri } GoogleSearch() { A_Clipboard := "" ; Clear clipboard variable Send "^c" ; Copy selected text to clipboard if !ClipWait(2) { MsgBox "Failed to copy text to clipboard." return } CopiedText := A_Clipboard SearchURL := 'http://www.google.co.uk/search?hl=en&safe=off&q="' UriEncode(CopiedText) '"' Run SearchURL ; Open the default web browser with the search URL } | | | Silviu Lungu Roumanie Local time: 13:36 anglais vers roumain
In tried ahk v2 script converter and got a working variant from your initial code. It works but I didn't tested very much. | | | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » AutoHotkey script to search Google for selection, or open URL (from any program) TM-Town | Manage your TMs and Terms ... and boost your translation business
Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.
More info » |
| Trados Studio 2022 Freelance | The leading translation software used by over 270,000 translators.
Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop
and cloud solution, empowering you to work in the most efficient and cost-effective way.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |