home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / lisp / mcl / 1554 < prev    next >
Encoding:
Text File  |  1992-11-07  |  2.9 KB  |  67 lines

  1. Path: sparky!uunet!news.encore.com!csar!foxtail!sdd.hp.com!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!data.nas.nasa.gov!taligent!apple!cambridge.apple.com!moon
  2. From: moon (David A. Moon)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: Need help launching application in MCL (from a data file)
  5. Message-ID: <9211052145.AA28573@cambridge.apple.com>
  6. Date: 5 Nov 92 21:46:49 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 53
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Full-Name: David Moon
  11. Original-To: dmg@goldilocks.LCS.MIT.EDU (David Goodine)
  12. Original-Cc: info-mcl@cambridge.apple.com
  13.  
  14. > Date: Thu, 5 Nov 92 16:27:14 EST
  15. > From: dmg@goldilocks.LCS.MIT.EDU (David Goodine)
  16. > I'm trying to write some code that will take a pathname for an arbitrary
  17. > file and launch the application that created the file.  I've managed to
  18. > launch an application explicitly, but can't figure out how to get the
  19. > mapping from the CREATOR of the file to the application (which the
  20. > finder seems to do internally).
  21. > The inside-mac documentation here has been no help... it seems to happen
  22. > magically somewhere between the finder and the process manager...
  23.  
  24. It is documented, but only for system 7.  You want the PBDTGetAPPL trap.  Try 
  25. the following:
  26.  
  27. ;;; -*- Mode: Lisp; Package: CCL -*-
  28.  
  29. (in-package CCL)
  30.  
  31. ;;; A handy subroutine, only works in system 7
  32. ;;; Returns the pathname of the application or nil if not found on any volume
  33. ;;; Several undocumented errors can occur, I hope I found them all
  34. (defun application-pathname (signature)
  35.   (rlet ((pb :dtpbrec)
  36.          (iopb :hparamblockrec))
  37.     (%stack-block ((name 256)) 
  38.       (setf (rref iopb :hparamblockrec.ioCompletion) (%null-ptr)
  39.             (rref iopb :hparamblockrec.ioNamePtr) name)
  40.       (loop for volume-index from 1 do
  41.         (setf (rref iopb :hparamblockrec.ioVolIndex) volume-index
  42.               (rref iopb :hparamblockrec.ioVRefNum) 0)
  43.         (let ((err (#_PBHGetVInfo iopb)))
  44.           (unless (zerop err)
  45.             (if (= err #$nsvErr)
  46.               (return-from application-pathname nil)
  47.               (error "_PBHGetVInfo error #~D" err))))
  48.         (setf (rref pb :dtpbrec.ioCompletion) (%null-ptr)
  49.               (rref pb :dtpbrec.ioNamePtr) name
  50.               (rref pb :dtpbrec.ioVRefNum)
  51.                (rref iopb :hparamblockrec.ioVRefNum))
  52.         (let ((err (#_PBDTGetPath pb)))
  53.           (unless (zerop err)
  54.             (unless (= err #$wrgVolTypErr)
  55.               (error "_PBDTGetPath error #~D" err))))
  56.         (setf (rref pb :dtpbrec.ioIndex) 0
  57.               (rref pb :dtpbrec.ioFileCreator) signature)
  58.         (let ((err (#_PBDTGetAPPL pb)))
  59.           (cond ((zerop err)
  60.                  (setf (rref iopb :hparamblockrec.ioDirID)
  61.                        (rref pb :dtpbrec.ioAPPLParID))
  62.                  (return-from application-pathname (%path-from-iopb iopb)))
  63.                 ((and (/= err #$afpItemNotFound) (/= err #$fnfErr))
  64.                  (error "_PBDTGetAPPL error #~D" err))))))))
  65.