topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 8:07 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: hotkey to launch google search in a new firefox tab  (Read 6474 times)

ottenm

  • Supporting Member
  • Joined in 2008
  • **
  • default avatar
  • Posts: 93
    • View Profile
    • Donate to Member
hotkey to launch google search in a new firefox tab
« on: July 23, 2014, 06:40 AM »
Sorry I can't quite get my head around a way to do this from farr.

I currently have a farr hotkey defined with the "Text for Search Edit Box" set to "search\s".  And "search" is defined as an alias with about 15 results, the first of which is a google search.  So when I use the hotkey I type my search text into farr and hit enter, which opens my browser (firefox) with the google results.

I have firefox set to open links like this in the current tab, which is what I prefer most of the time.  But there are times I'd basically like farr to open a new tab in ff and then open the google results there (effectively opening my results in a new tab, but without changing that preference in firefox).

I found 'sendkeys' in farr, but can't get my head around getting farr to switch from whatever app I start in, over to Firefox, then send the keys to open a tab, then go back to farr and run the 'search' alias.

Thanks for any help!

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: hotkey to launch google search in a new firefox tab
« Reply #1 on: July 24, 2014, 09:38 AM »
@mouser provided a rather nifty bit of code for AutoHotKey use (called Selectosurf) to do what you seem to want. You just select the text or URL that you want to search for, press the hotkeys Ctrl+Space (this can be changed), and the search engine of your choice (see lines 88, 89 in the code window below), and your browser opens a search result panel/window.
If you search on the DC Forum for Selectosurf, you will come up with these discussion threads:

I use it as per below, to invoke a duckduckgo search. It's rather fast. It puts the search string as a specific literal inside double quotes though, which you might want to change or vary.

Code: Autohotkey [Select]
  1. SelectoSurf:    ;Sends selected plaintext url or other string and opens it in a browser or search.
  2. ;  Based on SelectoSurf by [email protected]
  3. ;  see https://www.donationcoder.com/Forums/bb/index.php?topic=6714.0
  4. ; v 1.1.0, Jan 25, 2008 - improved browser option, added split-line reconstruction, added about box
  5. ; v 1.0.2, Nov 10, 2006 - initial release
  6. ;
  7. ; Select plaintext in any program and hit the hotkey (ctrl+space)
  8. ; If the text looks like a url or website name (like donationcoder.com), it will be opened
  9. ;  otherwise a google (or other) search will be confucted with the phrase.
  10. ;------------------------------------------------------------------
  11. ; ATTN, OPTIONAL: configure a specific browser overide, to bypass using default
  12. ;browserexe = iexplore.exe
  13. ;browserexe = C:\Program Files\Mozilla Firefox\firefox.exe
  14. ;------------------------------------------------------------------
  15. temp = %clipboard%      ; grab old clipboard
  16. Send, ^c                ; send ctrl+C to copy new text to clipboard
  17. Sleep 100               ; sleep a tiny bit to give a chance for clipboard to propage
  18. theurl = %clipboard%    ; *potential* url
  19. ;
  20. ; merge split lines
  21. StringReplace, theurl, theurl, `r`n,, All
  22. StringReplace, theurl, theurl, `r,, All
  23. StringReplace, theurl, theurl, `n,, All
  24. ;
  25. ; clean spaces
  26. StringReplace, theurl, theurl, %A_Space%,`%20, All
  27. ;
  28. ; Lets do some other common replacements
  29. StringReplace, theurl, theurl, hxxp:,http:, All
  30. StringReplace, theurl, theurl, hxxps:,http:, All
  31. StringReplace, theurl, theurl, h??p:,http:, All
  32. StringReplace, theurl, theurl, h??ps:,http:, All
  33. ;
  34. ; remove any leading or trailing () [] . " '
  35. theurl := RegExReplace(theurl, "^[\.\(\)\'\[\]""]+")
  36. theurl := RegExReplace(theurl, "[\.\(\)\'\[\]""]+$")
  37. ;--------------------------
  38. ; is it a full url
  39. isaurl = 0
  40. IfInString, theurl, http:
  41. {
  42.         isaurl = 1
  43. }
  44. else IfInString, theurl, https:
  45. {
  46.         isaurl = 1
  47. }
  48. else IfInString, theurl, mailto
  49. {
  50.         isaurl = 1
  51. }
  52. else IfInString, theurl, ftp:
  53. {
  54.         isaurl = 1
  55. }
  56. else IfInString, theurl, www.
  57. {
  58.         isaurl = 1
  59. }
  60. else IfInString, theurl, .com
  61. {
  62.         isaurl = 1
  63.         theurl = www.%theurl%
  64. }
  65. else IfInString, theurl, .net
  66. {
  67.         isaurl = 1
  68.         theurl = www.%theurl%
  69. }
  70. else IfInString, theurl, .org
  71. {
  72.         isaurl = 1
  73.         theurl = www.%theurl%
  74. }
  75. else
  76. {
  77.         ; @sign with no spaces is an email
  78.         ; ATTN: toddo
  79.         if (0==1)
  80.                 {
  81.                 ; add a mailto
  82.                 theurl = mailto:%theurl%
  83.                 isaurl = 1
  84.                 }
  85.         else
  86.                 {
  87.                 ; search for the string - note this makes isaurl true always, which is what we want.
  88.                 ;theurl = http://www.google.com/search?hl=en&q=`%22%theurl%`%22
  89.                 theurl = http://duckduckgo.com/?q=`%22%theurl%`%22
  90.                 isaurl = 1
  91.                 }
  92. }
  93. ;--------------------------
  94. ; launch it?
  95. if (isaurl = 1)
  96. {
  97.         ; beep?
  98.         ; SoundBeep
  99.        
  100.         ; launch explorer with url
  101.         if (browserexe != "")
  102.                 {
  103.                 Run, %browserexe% %theurl%
  104.                 }
  105.         else
  106.                 {
  107.                 Run %theurl%
  108.                 }
  109. }
  110. ;--------------------------
  111. ; restore clipboard
  112. clipboard = %temp%
  113. ;--------------------------
  114. ; all done
  115. return
  116. ;--------------------------

ottenm

  • Supporting Member
  • Joined in 2008
  • **
  • default avatar
  • Posts: 93
    • View Profile
    • Donate to Member
Re: hotkey to launch google search in a new firefox tab
« Reply #2 on: July 25, 2014, 05:05 PM »
Thanks a ton IaianB!

Riding on your script from Mouser, I made an ahk script to find Firefox, create a new tab, and open the search results:

;Control+Alt+h
^!h::
InputBox, UserInput, Search Text
if ErrorLevel
    return
IfWinExist, ahk_class MozillaWindowClass
{
   WinActivate, ahk_class MozillaWindowClass
  Sleep, 100
  Send, {CTRLDOWN}t{CTRLUP}
  Sleep, 100
  Run, http://www.google.co.../search?hl=en&q=`%22%UserInput%`%22
}
return

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: hotkey to launch google search in a new firefox tab
« Reply #3 on: July 25, 2014, 05:54 PM »
I made an ahk script to find Firefox, create a new tab, and open the search results
That could be very useful, not just for firefox but for other browsers.  Thanks for sharing it  :up:

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: hotkey to launch google search in a new firefox tab
« Reply #4 on: July 25, 2014, 09:30 PM »
Thanks a ton IaianB!
Riding on your script from Mouser, I made an ahk script to find Firefox, create a new tab, and open the search results:
...
_______________________________

I'm very pleased to see that it was of use/help.
I see that your nice and short script uses the AHK InputBox, and is browser-specific.

I am always interested in trying out scripts and proggies to test them to see whether they do what they were intended/designed for, and what makes them fail, and what they do when they fail or are presented with input that was not necessarily intended in their design - for example, what they might do when things cause them to fail in some manner.

Testing a script under different conditions is useful, because the good/effective or bad things about a script might not always be immediately apparent. In the case of Selectosurf some interesting points/features/possibilities are:
  • 1. Housekeeping: The script makes a copy of the Clipboard current state before sending a copy command to capture the text highlighted by the user. At the end of the script, the saved clipboard state is replaced, overwriting any changes that the script may have made to the clipboard whilst the script was running. So you won't see the copied text in (for example) the CHS (Clipboard Help and Spell) list of recently copied text (it's called the "QuickPaste" list in CHS). It is good practice for a script to do some tidy up housekeeping after itself like this. But you might not want that. You might want to (say) keep any text you searched for, retained in QuickText. You can modify the script to do that by commenting out the housekeeping bits.

  • 2. Browser: You can get it to use either the system default browser, or a specific browser which might not be the system default browser. This allows flexibility under the user's control.

  • 3. Search engine: You have to specify the search engine in the parameters sent to the browser. This allows flexibility/choice under the user's control. However, you could modify this to just passing the assembled search text to the browser address bar ("awesome bar"), which could have been already set to apply that browser's default search engine to whatever was put in the address bar. More user choice.

  • 4. Failure state: (Potentially very useful.) If the user does not select any text and presses the hotkeys to activate Selectosurf anyway, then the script does not fail (it makes a null copy capture) but picks up the last thing you happened to copy into the clipboard - could be an image or text, for example.
    If you happen to be setting about collecting lots of material and references to search, then knowing this enables you to turn the combination of Selectosurf and CHS' QuickPaste (or whatever other Clipboard manager you might be using) into an incredibly useful. time-saving combination tool. You could go around copying the chunks of text - which may be either specific strings of text that you want to research or which may include some such specific strings in disconnected form. You can then select (click on) each item in turn from the CHS QuickPaste list and invoke Selectosurf in the usual way, for that item (ensure your mouse is not selecting any text at the time).
    This works because selecting the item from the QuickPaste list pushes it into the Clipboard as "the last copied item", which is what Selectosurf falls back on when it makes a null copy capture (as above).
    Before you do that though, if the item is a larger lump of text containing some text that would be irrelevant for a required search, then you can quickly edit it in CHS to reduce it to just that specific text string that you want to search for, and that goes into the QuickPaste list.
    General note: You probably need to be mindful of whether you want the script to constrain the string to be an explicit literal field (inside double quotes):
    e.g. something like:
    •          
    Code: Autohotkey [Select]
    1. theurl = http://duckduckgo.com/?q=`%22%theurl%`%22
    or approximate (without quotes):
    •          
    Code: Autohotkey [Select]
    1. theurl = http://duckduckgo.com/?q=%theurl%
      - when it is sent/put into the search box, as this will necessarily govern the outcome - i.e., the search result.
      (After some experiment, I think I find the latter more useful.)

  • 5. Autocopy: If you have Firefox, you can use the AutoCopy extension:
    Select text on any web page and it will be automatically copied to the clipboard. It works in much the same way as does Trillian or mIrc.
    Paste on middle click into textboxes, the url bar, and the search bar.
    _______________________________________________
    For capturing text strings containing more than one word, you have to select them all using the mouse, whereupon they are copied to the Clipboard.
    For capturing text strings containing just one word, double-clicking on the single word selects and copies that single word to the Clipboard.
    As above in point 4, if using (say) CHS:
    You can then select (click on) each item in turn from the CHS QuickPaste list and invoke Selectosurf in the usual way, for that item. This works because selecting the item from the QuickPaste list pushes it into the Clipboard as "the last copied item".  Before you do that though, if the item is a larger lump of text containing some text that would be irrelevant for a required search, then you can quickly edit it in CHS to reduce it to just that specific text string that you want to search for, and that goes into the QuickPaste list.
    _____________________
    With a clipboard manager such as (say) CHS, this can be very handy/speedy when gathering reference strings, as it puts them into the "latest captures" list - the QuickPaste list. If you select a string, using the mouse, and then invoke Selectosurf, the selected item goes into the Clipboard (and thus the CHS QuickPaste list) before Selectosurf saves the Clipboard state and makes its own copy of the selected item (which copy is later expunged when the script exits).
    The degree of control possible over CHS puts the user in full control of using things like the QuickPaste list and even the content and order/sequence of items on it, making it an ideal tool for this sort of repetitive collection-and-research process.

I mention these points/features/possibilities because you describe your nice and short script as being derived from ("Riding on") the Selectosurf script, and your script uses the AHK InputBox, and is browser-specific.
The InputBox could be an area for potential process improvement, by eliminating it altogether when/if it is redundant.
It thus occurred to me that you might be unaware of the above Selectosurf points/features/possibilities. I imagined you manually typing each search string (text item) into the InputBox, and wondered how many times that might be repeated with different/new strings and how many hours that might consume over a researcher's lifetime, when one could perhaps easily automate the data capture aspect to a major extent, thus avoiding most/all of the manual input, and leaving you at liberty to use the freed up cognitive surplus for something more interesting/enjoyable.

So, just some thoughts. Hope they are not too jumbled.

I abhor using manual processes where automation can be more usefully applied, and I am often appalled when I come across some unnecessary and repetitive tedium that we have unwittingly imposed upon ourselves or others.

All kudos to @mouser and his Selectosurf and CHS.
« Last Edit: July 26, 2014, 12:40 AM by IainB, Reason: Minor corrections/additions for improved clarity. »