[OT] Free IE Context Menu Scripts, (Was WMI on Win98...)

D

D F

omega said:
In the case of your script, there are more fields for interaction. One
for the text editor to be used, one for the path to save clips. Would this
be a way to go, if you wanted to add an install vbs for your script? For
that one group of folks who might prefer such a method, over editing the
script directly for their custom paths.

All things tend to go from simple to complicated, but the scripts we
are talking about here are more like 'bread and butter' utility
scripts for those who really use scripting a lot. So (for this
subject), this will be it for me... (That is, NO elaborate install
procedure for now... just install manually.)

I am posting two VB scripts that have evolved into something I find
myself using a lot now! The first is a rewrite of the IE 'capture
selection' script discussed in the message thread "WMI on Win98, the
end of Batch as we knew it."

The reason I am so bold as to post them here, is 1) they are a result
of the discussion in the referenced thread, and 2) I find them
particularly useful to capture notes and links from various Web Pages
when I download Freeware programs.... They help me easily retain the
'reconnect' information for valuable Freeware. (e.g., Now, where did
I get that great program?...)

This is a cleaned up, VBScript only version of the 'Capture Selection
to file' script. The second script is an enhancement.... Here's what
they do.

Script: BrowserSourcePart.vbs (Context Menu: "Source Selected")

This script, when integrated into the Context Menu (right click) on MS
Internet Explorer (5.0+), captures the HTML of the Selected Text and
copies it to a temporary file (with a standard name). Then it
launches an Editor of your choice (that is, one you select by
modifying the script when you install it), and displays the file for
you. It is up to you to decide what to do next. The file it writes
is considered Temporary, and will be overwritten the next time you
copy a selection.

Script: CopyMiniPage.vbs (Context Menu: "Copy MiniPage")

This script is an extension of the previous one, and simply Wraps the
HTML clipping in an HTML Page Holder so the resulting file has a
pretty good chance of being a usable HTML reference file as it is.
(The temporary file saved is an HTML file, in this case.) Be aware
that the wrapping is probably usable, but I won't guarantee it.
Fortuntatly it appears that when IE offers up the selection, it also
takes care of a few HTML tag issues, so the text you get tends to have
balanced HTML tags, but that is NOT something addressed here. What IS
done for you: A BASE reference is added, based on the page URL, so
any relative links in the HTML data are still usable. (This is a very
useful feature.) Also, a plausable TITLE tag is added, indicating the
URL you are quoting, and the features of that can be changed if the
user modifies the script. (Or, you can edit the title in each file as
you retrieve it.) Finally (for reasons I cannot entirely justify) I
added a LINK REF="next" tag to the header which contains the complete
original URL found in the Address Bar. (This is the only guaranteed
pure reference to where the original page was, an it is intact,
including all the URL arguments. It does not appear that IE uses this
tag for anything.)

To manualy install these scripts, cut and paste them into files where
you want them to be, then MODIFY the Registration Script (see the end)
to correctly NAME the full path to these files, and Double-Click on
the edited .REG file to add the references into the registry. Then,
at the next startup of IE, your Context Menu will have the two new
entries.

Here are the modifications you should perform:

* Modify the strings in each script after USER: to name the files you
want, and the viewer tool (editor) you want to use.

* Modify the Registry Entry file to name the LOCATION of the files
correctly, being sure to leave the \\ in the file paths, as required
for .REG files.

* Double-Click the .REG file to add the entries to the registry...

* Enjoy the scripts...

That's it for me on this subject. (If you want more, I can only
say,... Hey, there are NewsGroups for VB scripting!! - This ain't it.)

D F

'------- Start of File "BrowserSourcePart.vbs" ----------
<html>
<head>
</head>
<body>
<script language="VBScript"><!--

Dim win, doc, sel, rng
Dim szsource
Dim viewerTool
Dim myFile

' Setup strings the USER should modify...

' USER:
' Pick one A viewer program that accepts a file argument
' Uncomment a choice to select it.
' viewerTool = "C:\Program Files\NoteTab Light\NoteTab.exe"
viewerTool = "notepad.exe"

' USER: Name the location to store a temporary file.
myFile = "C:\Temp\IESelect.txt"

' USER: This appears in the Title of the page produced.
myTitle = "Quoted from " ' Later we tack on the reference

'-------------------------------------
' Start the real work here...
set win = external.menuArguments
set doc = win.document
' the text the user selected
set sel = doc.selection
' an IHTMLElement containing all the html elements selected
set rng = sel.createRange()
' the html string composing the range
szsource = rng.htmlText

if (len(szsource) = 0) then ' Use all body
szsource = doc.body.outerHTML
end if

call WriteFileVB(szsource,myFile) ' Write the file
call ViewWithTool(viewerTool,myFile) ' Open Viewer and File

' exit the code at this point.

'------------------ subroutines ---------------------
sub WriteFileVB(passedText,storeFile)
' Write a file containing the selected text (complete with
' HTML markup).

Dim fso, outf ' Objects to support writing the output file.

Set fso = CreateObject("Scripting.FileSystemObject")

' According to the MS Documentation,
' the OpenTextFile parameters are...
' Opentext(file, Mode:1-Read 2-Write 8-Append, CreateFlag)
' Open the file, create if necessary, specify overwrite.
Set outf=fso.OpenTextFile(storeFile,2,True)
' Put the whole selection at once, but add a CR at the end.
outf.WriteLine passedText

set outf=nothing ' Release object, close the file
set fso=nothing
end sub

sub ViewWithTool(usersViewer,usersFile)
' Start a Viewing Tool named by the user, and view the
' file named by the user.

Dim WshShell, oExec ' Objects for system 'Shell'
Set WshShell = CreateObject("WScript.Shell")

' Note: If necessary, provide a complete path to the
' executable of usersViewer. Some tools (like notepad)
' are available on the PATH, or in the registry,
' and don't need a full path. If this procedure
' cannot find your viewer, then provide a complete
' path. For example, 'notepad.exe' works all by itself,
' but you may need to give the full path to something
' like NoteTab ...
' "C:\Program Files\NoteTab Light\NoteTab.exe"
' We also quote the file name here so that you can
' have spaces in it. If you use the START command,
' which can be very powerful to launch a related
' application, be aware the Win2K and XP have an
' updated START command where the second argument
' is treated as a Title if quoted. So, to have a
' workable START, the viewer you pass should be given as
' "START """" " (The """" produces "" in VB strings.)
' IF the command for the viewer is NOT as simple as
' 'tool.exe file.txt' then you may
' have to alter the command line to produce a workable
' combination of parameters...

Set oExec = WshShell.Exec(usersViewer & _
" """ & usersFile & """")

Set wshShell = nothing
Set oExec = nothing
end sub

//-->
</script>
</body>

</html>
'-------- End of BrowserSourcePart.vbs ------------------

'--------Start of File CopyMiniPage.vbs -----------------
<html>
<head>
</head>
<body>
<script language="VBScript"><!--

Dim win, doc, sel, rng
Dim szsource
Dim viewerTool
Dim myFile
Dim WeGotBody
Dim myBase, myTitle, myURL

' Setup strings the USER should modify...

' USER:
' Pick one A viewer program that accepts a file argument
' Uncomment a choice to select it.
viewerTool = "C:\Program Files\NoteTab Light\NoteTab.exe"
' viewerTool = "notepad.exe"

' USER: Name the location to store a temporary file.
myFile = "C:\Temp\IEMiniPage.htm"

' USER: This appears in the Title of the page produced.
myTitle = "Quoted from " ' Later we tack on the reference

'-------------------------------------
' Start the real work here...
set win = external.menuArguments
set doc = win.document
' the text the user selected
set sel = doc.selection
' an IHTMLElement containing all the html elements selected
set rng = sel.createRange()
' the html string composing the range
szsource = rng.htmlText

WeGotBody = False
if (len(szsource) = 0) then ' Use all body
szsource = doc.body.outerHTML
WeGotBody = True ' Indicate we have <body> tags
end if

myURL = myURLNoArgs(doc.URL) ' Remove ? arguments
myBase = myBaseUrl(doc.URL) ' Remove File Name

if WeGotBody then
szsource = "<html>" & vbCrLf & "<header>" & vbCrLf & _
"<title>" & mytitle & myURL & "</title>" & vbCrLf & _
"<LINK REF=""next"" HREF=""" & doc.URL & """ />" & vbCrLf & _
"<BASE HREF=""" & myBase & """ />" & vbCrLf & _
"</header>" & vbCrLF & szsource & vbCrLf & "</html>"
else
szsource = "<html>" & vbCrLf & "<header>" & vbCrLf & _
"<title>" & mytitle & myURL & "</title>" & vbCrLf & _
"<LINK REF=""next"" HREF=""" & doc.URL & """ />" & vbCrLf & _
"<BASE HREF=""" & myBase & """ />" & vbCrLf & _
"</header>" & vbCrLf & "<body>" & vbCrLf & _
szsource & vbCrLf & "</body>" & vbCrLf & "</html>"
end if

call WriteFileVB(szsource,myFile) ' Write the file
call ViewWithTool(viewerTool,myFile) ' Open Viewer and File

' exit the code at this point.

'------------------ subroutines ---------------------
sub WriteFileVB(passedText,storeFile)
' Write a file containing the selected text (complete with
' HTML markup).

Dim fso, outf ' Objects to support writing the output file.

Set fso = CreateObject("Scripting.FileSystemObject")

' According to the MS Documentation,
' the OpenTextFile parameters are...
' Opentext(file, Mode:1-Read 2-Write 8-Append, CreateFlag)
' Open the file, create if necessary, specify overwrite.
Set outf=fso.OpenTextFile(storeFile,2,True)
' Put the whole selection at once, but add a CR at the end.
outf.WriteLine passedText

set outf=nothing ' Release object, close the file
set fso=nothing
end sub

sub ViewWithTool(usersViewer,usersFile)
' Start a Viewing Tool named by the user, and view the
' file named by the user.

Dim WshShell, oExec ' Objects for system 'Shell'
Set WshShell = CreateObject("WScript.Shell")

' Note: If necessary, provide a complete path to the
' executable of usersViewer. Some tools (like notepad)
' are available on the PATH, or in the registry,
' and don't need a full path. If this procedure
' cannot find your viewer, then provide a complete
' path. For example, 'notepad.exe' works all by itself,
' but you may need to give the full path to something
' like NoteTab ...
' "C:\Program Files\NoteTab Light\NoteTab.exe"
' We also quote the file name here so that you can
' have spaces in it. If you use the START command,
' which can be very powerful to launch a related
' application, be aware the Win2K and XP have an
' updated START command where the second argument
' is treated as a Title if quoted. So, to have a
' workable START, the viewer you pass should be given as
' "START """" " (The """" produces "" in VB strings.)
' IF the command for the viewer is NOT as simple as
' 'tool.exe file.txt' then you may
' have to alter the command line to produce a workable
' combination of parameters...

Set oExec = WshShell.Exec(usersViewer & _
" """ & usersFile & """")

Set wshShell = nothing
Set oExec = nothing
end sub

function myURLNoArgs(documentURL)
' Find the URL, including the File Name, if any, but drop
' the Arguments, after the '?'
Dim ix, jx
' Default result
myURLNoArgs = documentURL
ix = InStrRev(documentURL,"?") - 1
if (ix > 0) then
myURLNoArgs = Left(documentUrl,ix)
end if
end function

function myBaseUrl(documentURL)
' Find the base URL, from the full document reference
' Eliminates the file-name part for many cases (not perfect)
Dim ix, jx
' Default result
myBaseUrl = documentURL
ix = InStrRev(documentURL,"/")
jx = InStr(documentURL,"//")
if ((ix > 0) AND (jx > 0)) then
' Check that we don't eliminate something already a BASE
if ( ix > jx + 1 ) then
myBaseUrl = Left(documentUrl,ix)
end if
end if
end function
//-->
</script>
</body>

</html>
'----- End of File "CopyMiniPage.vbs" -----------------

Caution: You may need to FIX Wrapped Lines in the following file,
which are broken by the posting software... Look for problems in the
lines containing "&Source Selected" and "Copy &MiniPage" and make them
ONE LINE with your editor... Modify the lines starting "@=" to point
to the place where you put the two script files (from above). File
names in this posting illustrate my setup only, and can be change to
whatever you want. MAKE SURE THAT YOUR PATH REFERENCES in the File
Names preserve \\ (to escape the \ in the path.

'----- Start of file RegisterEntries.REG -------------
REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt]

[HKEY_CURRENT_USER\Software\Microsoft\Internet
Explorer\MenuExt\&Source Selected]
@="C:\\Scripts\\MSIE\\BrowserSourcePart.htm"
"Contexts"=dword:00000030

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Copy
&MiniPage]
@="C:\\Scripts\\MSIE\\CopyMiniPage.htm"
"Contexts"=dword:00000030

'----- File RegisterEntries.REG ended on the previous line -----
Be sure to keep a blank line at the end of the .REG file.

Good Luck

D F
 
D

D F

omega <[email protected]> wrote in message news:<[email protected]>...

MY BLUNDER.... Both Script files in the previous post must be saved as
HTML files... These lines.... (which are only comments,...but
misleading)
'------- Start of File "BrowserSourcePart.vbs" ---------- [...]
'-------- End of BrowserSourcePart.vbs ------------------
'--------Start of File CopyMiniPage.vbs ----------------- [...]
'----- End of File "CopyMiniPage.vbs" -----------------

Should have been....
'------- Start of File "BrowserSourcePart.HTM" ---------- [...]
'-------- End of BrowserSourcePart.HTM ------------------
'--------Start of File CopyMiniPage.HTM ----------------- [...]
'----- End of File "CopyMiniPage.HTM" -----------------

That will make a difference when your context menu tries to access the
file. Make sure the script files themselves are saved as HTML (.HTM)
files.

Sorry about the mistake...

D F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top