From: daemon@cs.tulane.edu (0000-Admin(0000))
Subject: SunFlash: SUNERGY Newsletter Part 6
Nntp-Posting-Host-[nntpd-28534]: rex
Reply-To: <owner-sunflash@housun.Central.Sun.COM>
Organization: The Tulane CS Gateway
Distribution: lou
Date: Mon, 6 Apr 1992 09:42:11 GMT

----------------------------------------------------------------------------
                                                        The Florida SunFlash

                    SUNERGY Newsletter Part 6

SunFLASH Vol 40 #6					          April 1992 
----------------------------------------------------------------------------
********************************************************
*6*  Tips -N- Tricks: Custom Commands in File Manager  *
********************************************************

by John Lewis II, john.lewis@sun.com

      The File Manager Tool allows you to add your own  custom  commands
under  the "File / Custom Commands" menu. Once you add a new command, it
will always show up on the "Custom Commands" menu for  you  to  use.  In
Sunview/OpenLook and OpenWindows 2.0, you will see the command itself on
the menu, and in OpenWindows 3.0, you can have a label show  up  on  the
menu  that  represents  the  command. Let's look at some useful commands
that you can add to File Manager...

          _________________________________________________________
         | [ ]                 File Manager V3                     |
         |_________________________________________________________|
         | (File)     (View)     (Edit)     (Props)     (Goto:)    |
     ____|_________________________________________________________|
    |                   |                                          |
    | Open            > |                                          |
    |                   |__________________________________________|
    | Print           > |                                          |
    |                   |    __--_        __--_        __--_       |
    | Create File       |   |     |      |     |      |     |      |
    |                   |   |_____|      |_____|      |_____|      |
    | Create Folder     |    DIR_1        DIR_2        DIR_3       |
    |                   |                                          |
    | Find...           |     _             _            _         |
    |                   |    | L           | L          | L        |
    | Remote Copy...    |    |__|          |__|         |__|       |
    |                   |    FILE1         FILE2        FILE3      |
    |                  _|__________________                        |
    | Custom Commands >|                   |                       |
    |__________________|                   |                       |
         |             | Create Command... |                       |
         |             |                   |                       |
         |             | UNIX Shell...     |                       |
         |             |___________________|                       |
         |_________________________________________________________|

________________________________________________________________________

A SIMPLE EXAMPLE

Suppose you have a text file that you created with Text Editor, and  you
would like to spell-check it before printing it out.  UNIX has a command
called "spell" that you can use on a file that will  display  any  words
that were in your file but not in the system dictionary. You could go to
a shelltool and type "spell filename" but it will be  faster  to  spell-
check from File Manager.

First, menu select "Create Command"  under  "File  /  Custom  Commands".
Enter  the  command "spell $FILE". The word "spell" is the UNIX command,
and "$FILE" tells File Manager which file to perform the "spell" command
on.  This  is  a special name ($FILE) that has to be capitalized. If you
are using OpenWindows 3.0, you can give the command a label like  "Spell
Check  File",  which  will  be on the menu instead of the actual command
"spell $FILE". Now apply this change to the menu by pressing "Apply"  on
the pop-up window.

Next, select the file you want to spell-check. (The file icon  that  you
have  selected with the mouse, is the file represented by "$FILE" in the
command.)

Now, with the file highlighted, menu select your custom command, and any
words  not  found  in  the  system  dictionary  will be displayed in the
console window.

________________________________________________________________________

FILES

When you add commands to the menu, they are saved in a special  file  in
your   home   directory.   The  File  Manager  in  Sunview/OpenLook  and
OpenWindows 2.0 save the commands in a  file  called  ".fvcmd",  and  in
OpenWindows 3.0 they are saved in a file called ".fmcmd".

You can add to the files through the menu  selection  "Create  Command",
but when modifying, it may be easier to make the changes directly to the
file using vi or Text Editor. If you make changes this way, a  new  File
Manager will have to be launched to see the change on the menu.

________________________________________________________________________

MORE EXAMPLES

Now that you have spell-checked your text file, you may want to print it
out  with  a  different  font than the default, which is courier on most
printers. Try these commands for printing text files:

enscript -B -fHelvetica12 $FILE
enscript -B -fTimes-Roman13 $FILE

Here are some other commands to try:

ls -l $FILE                     (display long listing of file)
file $FILE                      (display type of file)
head $FILE                      (display first 10 lines of file)
tail $FILE                      (display last 10 lines of file)
compress $FILE                  (compress a file to a smaller size)
uncompress $FILE                (uncompress a compressed file)
cp `echo $FILE`% $FILE          (restore from backup "%" file)
cat $FILE > /dev/audio          (listen to audio file)
spell $FILE | fmt -46           (spell-check with more errors visible
                                 without scrolling the console window)

________________________________________________________________________

ADVANCED EXAMPLES - (OpenWindows 3.0 Only)

The example commands above have been  fairly  short.  You  could  create
commands  that  total  256  characters  on  the command line. You may be
wondering, "Why does a command ever need to be that long, and how  could
it  be displayed on the menu?". The answer is that it can't be displayed
on the menu, which is why the following  examples  are  only  for  those
using  OpenWindows 3.0, because you can put a command label on the menu,
and not see the long command.

The File Manager in OpenWindows 3.0 uses  the  special  variable  called
"$FILE",  and  another one called "$ARG" that lets you pass arguments to
the command. One argument you may want to pass to the "enscript" command
is  the  name  of a printer, so that it doesn't always have to go to the
default printer. Here are the entries needed  on  the  "Create  Command"
pop-up window that will let you select a printer:

             ----------------------------------------------
              MENU LABEL:
              Print Postscript Helvetica 12

              UNIX COMMAND:
              cat $FILE | enscript -B -fHelvetica12 -P$ARG

              PROMPT WINDOW:
              Yes

              PROMPT:
              Printer Name?
             ----------------------------------------------

You may notice a few things  about  the  above  command  that  could  be
improved.  It  would  be nice to have a text file unformatted so that it
wraps to what-ever size window  you  are  using,  but  then  prints  out
formatted,  with  the return characters aligned correctly. Let's add the
"fmt" command to format text before sending it to the printer:

cat $FILE | fmt -s -94 | enscript -B -fHelvetica12 -P$ARG

Another thing that you may notice, is that  when  the  prompt  asks  you
which  printer you want, you may just want to press the "Run" button and
have it go to the  default  printer,  without  typing  in  your  default
printer  name.  But  this  will give you an error message in the console
window, because you didn't give the "-P" argument  any  information.  We
can put the entire command inside a "C" shell and trap the error message
like this:

csh -cf "cat $FILE|fmt -s -94|enscript -BfHelvetica12 -P$ARG|& egrep -v
argument"

Obviously you can get carried away and create some very  long  commands.
Here  are  two examples that will allow the OpenWindows 3.0 user to send
and receive encoded mail files from Sunview/OpenLook and OpenWindows 2.0
mailtool users:

                          VERY LONG COMMAND #1

  --------------------------------------------------------------------
MENU LABEL:
OW3 File -> OW2 Mailtool User

UNIX COMMAND:
compress -cf $FILE>$FILE".Z";echo ' ';echo "Send`echo $FILE|
sed 's/\// /g'|fmt -1|tail -1`.Z to OW2 Mailtool User As Attachment"

     (Note that this must be one continuous line without a return)

  --------------------------------------------------------------------

                          VERY LONG COMMAND #2

  --------------------------------------------------------------------
MENU LABEL:
OW2 Mailfile -> OW3 File

UNIX COMMAND:
echo Creating File: `grep begin $FILE|sed -n 's/.Z{}$//p'|awk '{print $3}'`;
cat $FILE|sed -n 's/{}$//p'|uudecode;uncompress `grep begin $FILE|
sed -n 's/{}$//p'|awk '{print $3}'`;sleep 3;rm $FILE

      (Note that this must be one continuous line without returns)

OUTPUT WINDOW:
Yes

  --------------------------------------------------------------------

The output window is used in the above example because you  may  already
have  a  file  that  has the same name as the one about to be created. A
prompt from the uncompress command will ask if you  want  to  over-write
the  existing file. The output window also displays the name of the file
it is creating so you know which file to look for in file  manager  when
the process is complete.

________________________________________________________________________

CONCLUSION

With a little work, creativity, and UNIX knowledge, you can  incorporate
the  most-used  (or  most  required) commands in your organization, into
Menu Selectable Custom Commands that will enhance  the  productivity  of
your entire organization!

Newsgroups: lou.sun