1

Is there a way to get the first url for highlighted text from google? It's like we have keyboard integrated search on mobiles but not on desktops.

It is especially useful when I want to link to a wikipedia topic or software website on stackoverflow ...etc.

1

I just created a simple way to do it. It's not the best but it works well enough for me right now. I didn't customize it to match stackoverflow's formatting as I wanted it flexible for now. Will put it up on github later. Probably needs to be better to make it really work.

Save the following as Googlesearch.ahk and run it using autohotkey

; Search google for the highlighted word
; then get the first link address and put it on the Clipboard

^!r:: Reload

#+g::
    bak = %clipboard%
    Send, ^c
    ;clipboard = %bak%`r`n%clipboard%
    Query = %clipboard%
    wb := ComObjCreate("InternetExplorer.Application")
    ;wb := IEGet()
    wb.Visible := false
    wb.Navigate("www.google.com/search?q=" Query)
    While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
      sleep 100
    ; loop % (Nodes := wb.document.getElementById("rso").childNodes).length
    ;     Links_urls .= (A_index = 1) ? Nodes[A_index-1].getElementsByTagName("a")[0].href : "`n" . Nodes[A_index-1].getElementsByTagName("a")[0].href
    ; Msgbox %Links_urls%

    Nodes := wb.document.getElementById("rso").childNodes
    First_link := Nodes[0].getElementsByTagName("a")[0].href
    Clipboard = %First_link%
    TrayTip, First Link on Google Search, %First_link% `r`n Ctrl+V to paste the link
return

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.