Make a Google It tool to perform web searches from TextPad

Usage tips, posted by users. No questions here please.

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
KurtM
Posts: 1
Joined: Wed Nov 29, 2006 8:13 pm
Location: Houston, TX

Make a Google It tool to perform web searches from TextPad

Post by KurtM »

First post for me here -- so be gentle! (although I am a long time TextPad user, circa 2001).

I don't think this subject has been addressed in the forums yet. I did a search and didn't find any discussion of it. Here goes...

Sometimes when I am in the middle of writing VBScript or other administrative scripting, I forget how to use a particular function or method. Othertimes I just am curious how someone else has approached the same problem I am programming for. Like most folks I know in the industry, I usually just open up my browser and Google for it to see what pops up.

Being a bit of the lazy sort, I wanted to be able to be able to search for a topic or keyword on the Internet from right within TextPad, without leaving my open document window and typing something in elsewhere. Ideally the solution wouldn't require me to have to do much more than what I currently do on an Internet Explorer page -- which is right-click on a highlighted term or phrase in the web page and select Google Search from the resulting pop-up menu.

Thank goodness for TextPad's customizable Tools Menu. Although I couldn't come up with a slick 'right-click' method to perform a web search from within an open document in Textpad, I believe I came up with something that's just as easy and functionally as elegant.

There are basically just two steps involved in creating your own Google It tool for the TextPad Tools Menu:
  1. Add a custom tool entry to the Tools Menu.
  2. Configure its properties to invoke Internet Explorer and pass search parameters to Google's search engine.
Let's detail the above steps. The first one is very easy once you understand what type of menu item to add. (Note, unlike creating a new document class you don't need to close any open documents to customize the tool menu -- see How to Customize the Tools Menu in Help for more details.)
  1. Add a custom Tool entry:
    1. From the Configure menu, choose Preferences (or use the two-key shortcut Ctrl+Q, P)
    2. Select "Tools" in the left-hand window of the dialog box that just opened up.
    3. From the Tools form on the right-hand side, click the "Add" button and then from the list that drops down select "Program...".
    4. Using the File Selection dialog box that appears next, navigate your way to where your \Program Files folder is located and expand the Internet Explorer folder found there.
    5. Select the file "iexplore.exe" and then click on the dialog box's "Open" button to complete the program file selection process and add the new entry to the Tools list.
    6. You should now see a highlighted entry titled "Iexplore" at the bottom of the Tools list in the preferences dialog box. If you haven't clicked anywhere else yet, click once on the name "Iexplore" and rename it to "Google It" or whatever you'd like to call it.

      Don't worry if you did get in a hurry and lost focus on the Iexplore entry by clicking somewhere else or by clicking the Apply button. To rename any entry just click twice on it (like a really slow double-click) and type in the new name.
    7. Now click on the "Apply" button and your Google It tool entry will appear when you expand the Tools item in the left-hand window of the preferences dialog box.
  2. Now to edit the Google It tool properties:
    1. Still keeping the Preferences dialog box open, expand the Tools item in the left-hand window and select "Google It" (or whatever you named it earlier).
    2. You'll find that some of the properties have already been filled out for you by the Add Tools Wizard. That's okay. We really only need to change one of them anyways -- the "Parameters" property.
    3. In the "Parameters" field, enter the following:

      Code: Select all

      -nohome http://www.google.com/search?num=100&hl=en&lr=&q=$SEL
    4. Don't worry about the rest of the settings. You can leave the three checkboxes unchecked (Prompt for parameters, Run minimized, Save all documents first) and the "Initial folder" doesn't really apply so it's ok to leave it at $FileDir.
    5. Now just click on the "OK" button in the Preferences dialog box to close it.
Congratulations! You should now have a Tools menu entry called Google It. Let's try it out.

Go to any open document window in TextPad and double-click on a word -- like say on SWBemServices as seen in the following code snippet...

Code: Select all

Dim objWMIService     ! As WbemScripting.SWbemServices
and then click on the Tools menu to select "Google It" from the drop down list (or if your version is like mine you'll see a shortcut key hint next to the menu item that you can use next time. Mine is Ctrl+6 for Google It).

That should have just brought up an invocation of iexplore.exe and passed the formed Google URL parameter to it almost as if it were an HREF link. Neat huh?

This works because of the Tool Parameter Macro we specified when defining the properties of the tool. Remember the $SEL part of the URL specification? In the TextPad Help for Tool Parameter Macros it is defined as "Selected text in the active document."

So whatever you have selected in text will be passed to Google (limited to the first line of selected text in case you made a multiple-line selection). You can even select partial lines of code and successfully find things. I found this so slick that I set out to try and deliberately foul up a search by selecting wierd partial code. Really was not ever able to foul it up!

Try this out. Select part of a line of code from something like I show below.

Code: Select all

Set colPings = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
Really trying to throw it for a loop with unmatched parens and qoutes, I selected only this portion of the above code snippet and then used the Google It tool on it...

Code: Select all

.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address =
and I'll be danged if it didn't work! I not only got results for code samples that looked just like mine, but I also saw examples of better approaches for what I was trying to do.

A couple of notes about some of the techniques used in the above example. The reason I selected "Program..." rather than DOS Command, is because I'm assuming that Helios is putting the invocation into its own thread using some process-creation API, like CreateProcessEx. The is preferable to essentially creating two seperate process threads and memory allocations (one for the cmd.exe process and one for iexplore) which is what you'd do by using the DOS Command. Minor thing, but one is more efficient.

The switch "-nohome" used on iexplore.exe is to prevent it from first trying to open up a home page and then referencing our URL. You may see the "-new" switched used by some, but it's really not necessary here. You're getting a fresh process thread anyways. You could also use the "-k" switch (but I don't know why you would want to). That will open up IE in kiosk mode -- no status bar, no buttons, no menus. Netscape also responds to the "-k" switch in the same manner.

You may not want a few of the Google switches I illustrated with, especially if your native language is not English. Remove the "&hl=en" parameter from the Google url to default to your language setting in Google preferences.

I usually do not like to limit my searches to just English language pages so that is why I've added the "&lr=" limit parameter. Remove it if you want the searches to obey your set preferences for limiting searches to a specific set of languages.

Lastly, if you prefer some other number of search results to come up than 100 you can obviously change that too by specifying a different number for "num=100"


Hope everyone found this useful and instructional! Happy Googling.

Cheers,

Kurt Mayer
OnlyTextPad
Posts: 41
Joined: Sat May 20, 2006 9:10 pm
Location: Helsinki
Contact:

Awesome ! Here the configuration with Opera also

Post by OnlyTextPad »

AWESOME ! HERE THE CONFIGURATION WITH OPERA
REPLACE DIFFERENT OPERA PATH IF YOU HAVE ANY


Command:C:\Program Files\Opera\Opera.exe
Parameters:http://www.google.com/search?hl=en&clie ... un&q="$SEL"
Starting folder : C:\Program Files\Opera\

OK HERE THE COPY PASTE OF THE REG FILE FOR THE MOST LAZY ONES (ON YOUR OWN RISK !!! )
=====================COPY PASTE START

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Helios\TextPad 4\Tools\19]
"Properties"=hex:00,00,00,00,69,80,00,00,40,00,00,00
"MenuText"="GoogleItWithOpera"
"Command"="C:\\Program Files\\Opera\\Opera.exe"
"Parameters"="http://www.google.com/search?hl=en&client=opera&rls=en&hs=pun&q=\"$SEL\""
"Folder"="C:\\Program Files\\Opera\\"
"RE"=""

=====================COPY PASTE STOP
Last edited by OnlyTextPad on Wed Mar 07, 2007 1:51 pm, edited 1 time in total.
bveldkamp

Post by bveldkamp »

That's pretty useful; additionally, to start the default system browser, do this:
Configure > Preferences > Tools
Add > DOS Command
Type Google > OK > Apply
In the tree on the left, select Tools > Google
On the right:
Parameters: start http://www.google.com/search?q=$SELWORD
Check "Run Minimized" and "Close DOS Window", uncheck all others
Apply / OK

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Helios\TextPad 4\Tools\7]
"Properties"=hex:01,00,00,00,5d,80,00,00,46,00,00,00
"MenuText"="Google"
"Command"="cmd.exe"
"Parameters"="start http://www.google.com/search?q=$SELWORD"
"Folder"="$FileDir"
"RE"=""
Last edited by bveldkamp on Mon Jan 21, 2008 1:29 pm, edited 2 times in total.
FrassHead
Posts: 3
Joined: Wed Apr 05, 2006 11:10 pm

Post by FrassHead »

Any idea why this doesn't work with Firefox? I'd rather not even allow iExplorer to un on my machine.

FH
OnlyTextPad
Posts: 41
Joined: Sat May 20, 2006 9:10 pm
Location: Helsinki
Contact:

Try this only for firefox

Post by OnlyTextPad »

The reason is the dummy space in C:\Program Files
you would need to invoke the program with the start command
Trying to add dos command http://www.google.fi/search?q=$SEL works for me

Code: Select all

[HKEY_CURRENT_USER\Software\Helios\TextPad 4\Tools\20]
"Properties"=hex:01,00,00,00,6a,80,00,00,e8,00,00,00
"MenuText"="GOOGLEITWITHFIREFOX"
"Command"="cmd.exe"
"Parameters"="start /max firefox http://www.google.com/search?q=$SEL"
"Folder"="$FileDir"
"RE"=""
textpad-fan
Posts: 25
Joined: Sat Apr 21, 2007 5:41 pm

Post by textpad-fan »

Try this in the parameters field in order to use the Google's Define switch:

Code: Select all

-nohome http://www.google.com/search?num=100&hl=en&safe=off&q=define%3A$SEL&btnG=Search
aabe
Posts: 1
Joined: Sat May 03, 2008 8:57 pm

Google IT tool

Post by aabe »

:D Good Tool! Works great!
HerNameWasTextPad
Posts: 59
Joined: Fri Apr 18, 2008 3:25 am

Post by HerNameWasTextPad »

Don't ya just love this program?

When I hear some users say things like, "TextPad is an aging program," I honestly don't know what they mean. Maybe they just haven't discovered for themselves what TextPad can do.

Thanks for sharing this in the forum.
I came in on 4.5 in 2001, moved to 4.7.2 in 2004, moved to 4.7.3 in 2007, moved to 5.4 in 2010, and am excited about 2013. I've said it many times before, and I'll say it many times again: "I love this program."
HerNameWasTextPad
Posts: 59
Joined: Fri Apr 18, 2008 3:25 am

Post by HerNameWasTextPad »

By the way, just to make sure that the palette is complete, so to speak, are you aware of the default ability to position the cursor on an active document's URL and right-click to select the open command?

Alternatively, position the cursor on a URL and Ctrl+Shift+G.

Help -> Help Topics -> Index -> URL -> Display

With both this and the new Google It tool, manually launching a browser can be nothing more than an occasional diversion!
I came in on 4.5 in 2001, moved to 4.7.2 in 2004, moved to 4.7.3 in 2007, moved to 5.4 in 2010, and am excited about 2013. I've said it many times before, and I'll say it many times again: "I love this program."
mandela10
Posts: 1
Joined: Sat Jun 06, 2009 12:52 am
Contact:

Post by mandela10 »

Nice tool. i have just tried it, it works great.
Post Reply