This was a 5 minute fix, took 10 minutes to test, and 3 days to find the time to post the update. I'll also added code to determine if gmht.exe exists in Awasu's installation directory before attempting to call it,
As discussed in this thread, http://www.awasu.com/forums/viewtopic.php?t=8336, Awasu's extensibility can make it relatively simple to retrieve the full web page referenced by a feed item and save it as an MHT file. An MHT file is a Microsoft "Web Archive" file format that stores the complete web page in a single file. It's basically a MIME multi-part format (http://en.wikipedia.org/wiki/MIME) similar to richly formatted email messages; all images are base-64 encoded so the file size increases somewhat, but with images embedded within the resultant MHT file, it is a highly portable file format for Windows/Internet Explorer users.
Apparently, the MHT file format is the file format that Awasu uses to store pages for offline reading and Taka was kind enough to share how to call the gmht.exe program to save a web page as an MHT file, so...
I wrote a Send to tool to save the page referenced by a feed item to an MHT file in a directory you specify. It's written in VBScript so it should run on any modern version of Windows right out of the box, and the source code it completely visible for you to modify.
Setup:
Copy and paste the following text into an empty text file and save it as: SaveAsMHT.vbs
Code: Select all
Option Explicit
Const WshFinished = 1
Const strAppTitle = "Awasu Save as MHT Send to tool"
Const strGMHTExe = "gmht.exe"
Const strGMHT_Err_No_Arguments = "Invalid arguments."
Const strGMHT_Err_Bad_syntax = "Can't download to MHTML: Invalid syntax"
Const strGMHT_Err_Unknown = "Can't download to MHTML: Unknown error 0x800C0005"
Const strGMHT_Err_Dispatch = "Can't download to MHTML: IDispatch error #24"
Dim strURL ' As String
Dim strTitle ' As String
Dim strOutputDir ' As String
Dim strDestFile ' As String
Dim WshShell ' As WScript.Shell
Dim oExec ' As WScript.WshExec
Dim strStdOut ' As String
Dim strStdErr ' As String
Dim strAwasuProgDir ' As String
Dim fso ' As Scripting.FileSystemObject
Dim fldrTemp ' As Scripting.Folder
Dim fileMHT ' As Scripting.File
Dim strMsg ' As String
Dim regEx ' As VBScript.RegExp
If WScript.Arguments.Count < 3 Then
MsgBox "Error: Invalid syntax - cscript SaveASMHT.vbs URL Title OutputDirectory"
WScript.Quit(1)
End If ' WScript.Arguments.Count < 3
strURL = Trim(WScript.Arguments.Item(0))
strTitle = Trim(WScript.Arguments.Item(1))
strOutputDir = Trim(WScript.Arguments.Item(2))
Set fso = CreateObject("Scripting.FileSystemObject")
'----------------------------------------------------------------------------------
' If the output folder doesn't exist, exit with an error message.
'----------------------------------------------------------------------------------
If Not fso.FolderExists(strOutputDir) Then
Set fldrTemp = fso.CreateFolder(strOutputDir)
strMsg = "Error: Output folder: """ & strOutputDir & """ does not exist."
Msgbox strMsg, vbOkOnly, "Error: " & strAppTitle
WScript.Quit(2)
End If ' Not fso.FolderExists(strOutputDir)
strURL = Replace(strURL, "%3F", "?") ' Un-url encode the question mark
' Append a trailing backslash if it doesn't already exist.
If Right(strOutputDir, 1) <> "\" Then
strOutputDir = strOutputDir & "\"
End If ' Right(strOutputDir, 1) <> "\"
'----------------------------------------------------------------------------------
' Find Awasu's installation directory, that's where gmht.exe lives.
'----------------------------------------------------------------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
strAwasuProgDir = WshShell.CurrentDirectory & "\"
If Not fso.FileExists(strAwasuProgDir & strGMHTExe) Then
strMsg = "Error: """ & strAwasuProgDir & strGMHTExe & """ does not exist " & _
vbCrLf & "in the same directory as Awasu.exe." & _
vbCrLf & "Please move/copy """ & """ strGMHTExe into the same directory as awasu.exe."
Msgbox strMsg, vbOkOnly, "Error: " & strAppTitle
WScript.Quit(3)
End If ' Not fso.FileExists(strAwasuProgDir & strGMHTExe)
'----------------------------------------------------------------------------------
' Call gmht.exe, wait for the return message.
'----------------------------------------------------------------------------------
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(strAwasuProgDir & strGMHTExe & " " & strURL & " 0")
Do While oExec.Status <> WshFinished
Loop ' While oExec.Status <> WshFinished
'----------------------------------------------------------------------------------
' gmht.exe has completed, read stdout and stderr,
' remove the trailing carriage return/line feed characters.
'----------------------------------------------------------------------------------
strStdOut = Replace(oExec.StdOut.ReadAll(), vbCrLf, vbNullString)
strStdErr = Replace(oExec.StdErr.ReadAll(), vbCrLf, vbNullString)
'----------------------------------------------------------------------------------
' If stderr has a value display an error message and exit.
'----------------------------------------------------------------------------------
Select Case strStdErr
Case strGMHT_Err_No_Arguments
MsgBox "Error: " & strGMHT_Err_No_Arguments & vbCrLf & "Please correct your arguments to """ & strAppTitle & """", vbOkOnly + vbCritical, "Error: " & strAppTitle
WScript.Quit(4)
Case strGMHT_Err_Bad_syntax
MsgBox "Error: " & strGMHT_Err_Bad_syntax & vbCrLf & "Please correct your arguments to """ & strAppTitle & """", vbOkOnly + vbCritical, "Error: " & strAppTitle
WScript.Quit(5)
Case strGMHT_Err_Unknown
MsgBox "Error: " & strGMHT_Err_Unknown & vbCrLf & "Verify your URL.", vbOkOnly + vbCritical, "Error: " & strAppTitle
WScript.Quit(6)
Case strGMHT_Err_Unknown
MsgBox "Error: " & strGMHT_Err_Dispatch & vbCrLf, vbOkOnly + vbCritical, "Error: " & strAppTitle
WScript.Quit(7)
End Select ' strStdOut
'----------------------------------------------------------------------------------
' Move the MHT to the output directory and remane it to the title of the feed item.
'----------------------------------------------------------------------------------
strDestFile = strOutputDir & CleanFileName(strTitle) & ".mht"
On Error Resume Next
If fso.FileExists(strDestFile) Then
fso.DeleteFile strDestFile
If Err.Number > 0 Then
MsgBox "Error: " & Err.Number & " - " & Err.Description & vbCrLf & "The file """ & strDestFile & """ must be locked by another application.", vbOkOnly + vbCritical, "Error: " & strAppTitle
WScript.Quit(8)
End If ' Err.Number > 0
End If ' fso.FileExists(strDestFile)
fso.MoveFile strStdOut, strDestFile
' Uncomment the following line (remove the leading apostrophe) to display a confirmation message box
'MsgBox """" & strURL & """ has been saved as """ & strDestFile & """", vbOkOnly, strAppTitle
' Replace invalid Windows file system characters with underscores
Function CleanFileName(strTitle)
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "[\\\/:*?<>""]"
CleanFileName = regEx.Replace(strTitle, "_")
End Function ' CleanFileName(strTitle)
Define a new Send to tool named "Save as MHT" (or whatever you want to call it). In the command box, enter the following command line:
Code: Select all
wscript "PathToWhereYouSavedTheFile\SaveAsMHT.vbs" {%URL%} "{%ITEM-METADATA% name!}" "Path to your output directory"
To set up a Send to tool click Edit->Send to->Organize
http://www.awasu.com/help/2.4/Productiv ... Tools.html
Pay special attention to the quotation marks in the above command line. Due to the way that most runtime environments pass space-delimited arguments via the command line, any argument that may contain embedded spaces needs to be wrapped with quotation marks. The URL should be ok; but the item's title, path to the Send to tool, and the output directory will all probably contain embedded spaces so you should wrap them with quotes.
Also the "Command" field of the "Organize send-to's" dialog box is limited to 235 characters. This should be enough characters to hold the complete command, as long as you don't use really long paths to the SaveAsMHT.vbs file and/or the output directory. If you must use really long paths that exceed 235 characters you can write a .BAT file that contains the all of the hard-coded portions of the above command and just pass in the URL and Title.
By making the output directory a parameter to the SaveAsMHT.vbs script you can actually define several instances of "Save as MHT" Send to tool, with different output directories, e.g. "Save as MHT, Health", "Save as MHT, IT", "Save as MHT, News", etc.
Usage:
Open up a Channel Summary Template (CST) that contains the Send to link (any standard Awasu CST). Hover your mouse over the Send to link and select "Save as MHT" from the popup menu. A DOS window will open for a few seconds and if everything goes correctly, an MHT file will be created in the output directory you specified. The MHT file name will be the feed item's title with illegal Windows file system characters replaced with underscores. By default, no confirmation message is displayed, but there is a line of code towards the bottom of the script that you can uncomment (remove the leading apostrophe) if you want a confirmation message with each save.
Error messages will be displayed if:
- The output directory does not exist
1) Zero or too few arguments are passed
2) The gmht.exe program is not in Awasu's installation directtory
3) The URL is invalid
4) An existing file exists and it is locked by another process (otherwise existing files are silently overwritten).
If you have any problems with setup or running it, post a reply and I'll try to help you.