apphelper - a generic wrapper for email attachments or web browser file helpers, offering both save and view choices
apphelper [{-t|+t|-T title}] file [{-n|-y}]] [-d savedir] [-i type] [-p pager] [arg1opts...] viewer [viewer-args...]
Apphelper is a generic handler for a file. It was originally coded for use with netscape and mozilla which persist in directly opening files they have handlers for, offering no handy ``save as?'' accompaniment. This was particularly aggravating for PDF files, which I often want to keep around for later perusal.
Apphelper offers to view the file with the named viewer and after viewing, to save the file in a location of your choice.
The following terminal related options must preceed the filename.
Open a fresh terminal window in which to run apphelper. Generally desirable when invoking inside a GUI web browser.
Do not open a terminal window.
Specify the title of the fresh terminal in which to run apphelper. Implies the -t option.
After the terminal related pre-file options comes the file designation. Usually this will be a filename, however the following notations are also supported:
Read data from stdin. This will be placed in a temporary file.
Names commencing with http:// or ftp:// are taken to be URLs and fetched.
Specify a default directory in which to save files. Lacking this, use the value of the envvar $SAVEDIR or $HOME/dl if that is not set.
No: do not run the viewer program. The default is to ask first.
Yes: always run the viewer program. The default is to ask first.
No: do not offer to save the file. The default is to ask.
Yes: save the file without asking. The default is to ask.
Ask: ask to save the file even if the file's already there.
Auto: don't ask to save the file if the file's already there. The default is to auto.
Extract the file (if we know how)
with the x(1) command
and run apphelper on each component.
Trace execution of subcommands.
Specify the MIME type. Otherwise the type will be guessed from the file content.
Supply an argument for arg1, one of
-discard, -end, -n.
If specified,
the view will be invoked via arg1.
See arg1(1cs) for semantics.
This permits mailcap entries like this:
image/jpeg; ah %s -end xv; gui
which will correctly invoke xv with the possibly modified filename ah may use.
Apphelper first asks whether to view the file, offering the supplied view command in [square brackets] as the default. Pressing return or entering ``y'' or ``yes' accepts this default and runs the viewer. Entering ''n`` or ''no`` skips running the viewer. Other answers are taken to be the name (and optional arguments) of a viewing program.
If the viewer has a nonzero exit code (failure) then this is reported and the user is prompted for an alternative viewing program. Pressing return or entering ``n'' or ``no'' skips the second attempt. Other answers are taken to be the name (and optional arguments) of a viewing program.
After the view phase apphelper offers to save the file with the default pathname in [square brackets]. Pressing return or entering ``n'' or ``no'' skips the save. Entering ``y'' or B``<yes>'' saves the file under the supplied filename. Entering a string commencing with a bang (`!') performs a shell escape, running the tail of the string in the user's shell. Occurences of bangs in the command are replaced by the last command run from this instance of apphelper. Occurences of percents (`%') in the command are replaced by the filename.
Other answers are taken to be a different filename under which to save the file.
If the file is to be saved then the save filename is examined. If it starts with a tilde (``~'') then the leading ~ or ~username is replaced with the approriate home directory path. Relative pathnames are taken to be relative to the default save directory.
If there is a percent (``%'') present then the rightmost precent is replaced with the basename of the attachment name. This is useful for repairing truncated filenames on attachments.
If the filename points at a directory then the file is saved inside that directory with the basename of the attachment name.
If the filename ends in a dash (``-'') then the basename of the attachment name is appended. This is useful for attaching a prefix to some poorly chosen generic attachment name (like ``10.pdf'').
If after all this the target filename already exists
then the two files are compared.
If they are the same
then no action is taken.
If they differ
the then new file is copied onto the existing with via cp(1)
with the -i option,
leaving it up to cp(1) to ask questions.
My .mailcap file contains this line for JPEG files:
image/jpeg; apphelper %s -y xv
which causes mutt(1),
on pressing enter on a JPEG attachment,
to hand JPEG files to apphelper
which runs xv(1) immediately
and then offers a save option.
This mailcap line:
application/pdf;apphelper %s -y xpdf
causes mozilla to run xpdf(1) to view PDF files
and then to offer a save option.
Cameron Simpson <cs@zip.com.au> 18jun1998