.key number
.bra {
.ket }
.def number 0

; This recursive script comes courtesy of Mastering AmigaDOS scripts
; another great volume in the Mastering AmigaDOS series
; Mastering AmigaDOS scripts will be published in mid 1991
; by Bruce Smith Books
; This trinket written by Mark Smiddy"
; for Amiga Format readers

; THIS VERSION REPLACES THE ONE ON AFT 19 WHICH NEEDS 1MEG TO RUN
; SORRY ABOUT THAT!

; IT MUST HAVE THE NAME OF INSTALLPRINTER

if "{number}" EQ "0"
 echo "Easy Printer Driver setup - V1.2*n"
 echo "Written by *e[33mMark Smiddy*e[31m for *e[33mAmiga Format*e[31m"
 echo "From Mastering AmigaDOS scripts"
 echo "Another volume in the Mastering AmigaDOS 2 series"
 echo "The most informed AmigaDOS reference EVER!*n*n"

 if not exists t:Smiddy
  echo "Wait - copying commands to resident list...*n*n*n"
  resident c:echo add
  resident c:if add
  resident c:else add
  resident c:endif add
  resident c:copy add
  resident c:delete add
  resident c:join add
  resident c:edit add
  resident c:assign add
  resident c:execute add
  resident c:type add
  resident c:list add
  resident c:ask add
  resident c:search add
  resident c:makedir add
  copy installprinter t:
  echo >t:Smiddy "Working..."
 endif

 if not exists t:drivers
  makedir t:drivers
  echo "*nInsert the disk marked *"Extras 1.3*" in df0:"
  ask "Then press return..."
 endif

 list df0:devs/printers lformat "%s" to t:print
 list df0:devs/printers lformat "       COPY from *"%s%s*" to t:drivers quiet" to t:copyprint
 type >t:printers t:print opt n
 type t:printers
 echo "*nSelect your printer and enter its " noline
 execute t:InstallPrinter ?
 echo "*nInsert the disk marked *"Workbench 1.3*" in df0:"
 ask "Then press return..."
 if exists t:Command1
 execute t:Command1
;
; This next bit runs Preferences for you
; BUT it allows you to modify the preferences on ANY disk!
; This way you can have more than one printer disk... etc.
;
 ask "*nRun Preferences now?"
  if warn
   assign devs: df0:devs
   if exists df0:Prefs/Preferences
     df0:Prefs/Preferences PRINTER
   else
    echo "Preferences program missing/renamed"
    ask "Shall I try the boot disk?"
    if warn
     if exists sys:Prefs/Preferences
      sys:Prefs/Preferences PRINTER
     else
     echo "Blow me! That one's missing 'n all guv!"
     endif
    endif
   endif
   assign devs: sys:devs
 endif
 echo "All done... cleaning up"
 endif

 if "{number}" NOT EQ ""
  delete >nil: t:#? all QUIET
  resident echo remove
  resident assign remove
  resident if remove
  resident endif remove
  resident copy remove
  resident type remove
  resident execute remove
  resident join remove
  resident edit remove
  resident list remove
  resident ask remove
  resident else remove
  resident search remove
  resident makedir remove
  resident delete remove
 endif
endcli
else


;
; Here we use the auto EDIT macros!
; This is covered with loads of examples in
; Mastering AmigaDOS volumes I and II
; This is pretty complex stuff- but it does work!


 search >nil: t:printers search " {number} "
 if warn
  echo "Can't find that printer on my list..."
  echo "Program exiting"
  endcli
 else
  echo >t:auto1 "{number}d;7#;n;0d"
  echo >t:auto2 "cl//"
  echo >t:part0 ""
  echo >t:part1 "COPY from t:drivers/" noline
  echo >t:part3 " to df0:devs/printers" noline
  echo >>t:printers ""
  echo >>t:copyprint ""
  join t:part0 t:printers as t:printx
  edit from t:printx to t:part2 with t:auto1 ver=nil:
  join t:part1 t:part2 t:part3 as t:command
  edit t:command to t:command1 with t:auto2 ver=nil:
  echo "*n Your selection was: " noline
  type t:part2
  join t:part0 t:copyprint as t:copyx
  edit t:copyx to t:command3 with t:auto1 ver=nil:
  execute t:command3
  echo " (That noise was just me copying the driver to RAM:)"
 endif
endif

