home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / next / software / 3627 < prev    next >
Encoding:
Text File  |  1993-01-25  |  5.2 KB  |  192 lines

  1. Newsgroups: comp.sys.next.software
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!news
  3. From: magnus@Fisher.Stanford.EDU (Magnus Nordborg)
  4. Subject: Submission: Shell scripts to launch NeXTstep applications from command line
  5. Message-ID: <1993Jan25.223902.13579@leland.Stanford.EDU>
  6. Keywords: csh, open, Mail
  7. Sender: news@leland.Stanford.EDU (Mr News)
  8. Organization: DSO, Stanford University
  9. Date: Mon, 25 Jan 93 22:39:02 GMT
  10. Lines: 180
  11.  
  12.     Below are two csh scripts that launch NeXTstep applications from the  
  13. command line.  The first, "nxlaunch", will let you type "nxlaunch Mail" instead  
  14. of "/NextApps/Mail.app/Mail &" or "nxlaunch -o Mail" instead of "open  
  15. /NextApps/Mail.app".  Thus you save typing, and don't have remember the path of  
  16. every application.  
  17.  
  18.     There is one very useful difference between launching via "open (-o)"  
  19. or directly in background -- using "open" is just like clicking on the app,  
  20. running it the other way is literally launching it from the command line.  For  
  21. example, if you have a terminal open, and use "su" to become another user, then  
  22. type "nxlaunch Mail", that user's mail will be read, whereas the "nxlaunch -o  
  23. Mail" would not.
  24.  
  25.     This is also useful since "nxlaunch" also takes a "-NXHost" argument:
  26. If I sit at localhost (PublicWindowServer) and rlogin to remotehost, then type  
  27. "nxlaunch -NXHost localhost Mail", my mail on remotehost will be read, whereas  
  28. "nxlaunch -o -NXHost localhost Mail" would read mail on localhost.
  29.  
  30.     To make this last feature more useful, there is a second script,  
  31. "nxrsh", that is equivalent to "xrsh". Thus you can type (assuming a .rhosts  
  32. file, and the presence of "nxlaunch" on remote host) "nxrsh remotehost Mail".
  33.  
  34.     These script are public domain, and without any guarantees. Please send  
  35. me improvement and bug reports.
  36.  
  37. ###################### nxlaunch: cut below this line ######################
  38. #! /bin/csh -f
  39. #
  40. #    Finds and launches a NeXTapp from a shell, thus saving you the
  41. #        trouble of remembering and typing the full path.
  42. #
  43. #    by Magnus Nordborg <magnus@fisher.Stanford.EDU> 
  44. #        Wed Jan 20 13:31:38 PST 1993
  45. #
  46.  
  47. set flags
  48. set useopen
  49.  
  50. switch ( $#argv )
  51. case 1:
  52.   if ( $argv[1] =~ -h* ) then
  53.     goto usage
  54.   else
  55.     set app = $argv[1]
  56.   endif
  57.   breaksw
  58. case 2:
  59.   if ( "$argv[1]" == "-o" ) then
  60.     set useopen = 1
  61.     set app = $argv[2]
  62.   else
  63.     goto usage
  64.   endif
  65.   breaksw
  66. case 3:
  67.   if ( $argv[1] == "-NXHost" ) then
  68.     set app = $argv[3]
  69.     set flags = "-NXHost $argv[2]"
  70.   else
  71.     goto usage
  72.   endif
  73.   breaksw
  74. case 4:
  75.   set useopen = 1
  76.   set app = $argv[4]
  77.   if ( "$argv[1]" == "-o" && $argv[2] == "-NXHost" ) then
  78.     set flags = "-NXHost $argv[3]"
  79.   else if ( $argv[1] == "-NXHost" && "$argv[3]" == "-o" ) then
  80.     set flags = "-NXHost $argv[2]"
  81.   else
  82.     goto usage
  83.   endif
  84.   breaksw
  85. default:
  86.   goto usage
  87.   breaksw
  88. endsw
  89.  
  90. # check to see where Apps reside
  91. /usr/bin/dread Workspace ApplicationPaths >& /dev/null    # defined?
  92. if ( $status ) then
  93.   set vmpath = (~/Apps /LocalApps /NextApps /NextDeveloper/Apps /NextAdmin  
  94. /NextDeveloper/Demos)
  95. else
  96.   set tmp = `/usr/bin/dread Workspace ApplicationPaths`
  97.   set vmpath = (`echo $tmp[3] | /bin/awk -F: '{for(i=1;i<=NF;i++) print $i}'`)
  98. endif
  99.  
  100. # find the App
  101. foreach d ( $vmpath )
  102.   if ( -ed $d ) then
  103.     if ( -ed ${d}/${app}.app ) then
  104.       if ( $useopen ) then
  105.         /usr/bin/open $flags ${d}/${app}.app
  106.       else
  107.         ${d}/${app}.app/${app} $flags &
  108.       endif
  109.       exit 0
  110.     else if ( -ex ${d}/$app ) then        # not in app wrapper
  111.       if ( $useopen ) then
  112.         /usr/bin/open $flags ${d}/$app
  113.       else
  114.         ${d}/$app $flags
  115.       endif
  116.       exit 0
  117.     endif
  118.   endif
  119. end
  120.  
  121.  
  122. which echo2 >& /dev/null            # public domain: echo to stderr
  123. if ( $status ) then                #  -- use it if it exists
  124.   echo "$0 : $app not found"
  125.   exit 1
  126. else
  127.   echo2 "$0 : $app not found"
  128.   exit 1
  129. endif
  130.  
  131. usage:
  132. which echo2 >& /dev/null            # public domain: echo to stderr
  133. if ( $status ) then                #  -- use it if it exists
  134.   echo "Usage: $0 [-o][-NXHost hostname] NeXTapp"
  135.   echo '-o:   use "open" to launch'
  136.   exit 1
  137. else
  138.   echo2 "Usage: $0 [-o][-NXHost hostname] NeXTapp"
  139.   echo2 '-o:   use "open" to launch'
  140.   exit 1
  141. endif
  142.  
  143. ###################### nxrsh: cut below this line ######################
  144. #! /bin/csh -f
  145. #
  146. #    nxrsh -- an equivalent of xrsh
  147. #
  148. #    Usage: nxrsh hostname NeXTapp
  149. #
  150. #    by Magnus Nordborg <magnus@fisher.Stanford.EDU> 
  151. #        Wed Jan 20 13:31:38 PST 1993
  152. #
  153. #    Bugs: I have not been able to come up with a clever way of
  154. #          finding the correct HOSTNAME -- it has to be set in ".login"
  155. #          My other shell script, "nxlaunch", is needed to find the app.
  156. #
  157. #             There should be a way for this script to make the
  158. #             machine PublicWindowServer temporarily -- let me know
  159. #             if you find one...
  160. #
  161.  
  162. set openflag
  163.  
  164. if( $#argv ) then
  165.   if( "$argv[1]" == "-o" ) then
  166.     set openflag = "-o"
  167.     shift
  168.   endif
  169. endif
  170.  
  171. if( $#argv != 2 ) then
  172.   echo "Usage: nxrsh [-o] hostname NeXTapp"
  173.   echo '-o:   use "open" to launch'
  174.   exit 1
  175. endif
  176.  
  177. if( ! $?HOSTNAME ) then
  178.   echo "Environment variable HOSTNAME not set"
  179.   exit 1
  180. endif
  181.  
  182. # launch it on remote host using "nxlaunch"
  183. /usr/ucb/rsh $argv[1] "nxlaunch $openflag -NXHost $HOSTNAME $argv[2]" &
  184.  
  185. --
  186.  
  187.  
  188.         Magnus Nordborg
  189.         Department of Biological Sciences
  190.         Stanford University
  191.         magnus@fisher.stanford.edu (NeXT mail preferred)
  192.