[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I'm trying to have lisp launch an application (its not working)



To do this I'm attempting to use the applevents toolkit and the Open
Selection applevent for the finder. I've written:

(require 'appleevent-toolkit)

(defconstant $kAEOpenSelection :|sope|)
(defconstant $kAEFinderEvents :|FNDR|)
(defconstant $keySelection :|fsel|)

(defun create-alias-record (the-desc path)
  (rlet ((alias :aliashandle))
    (let ((namestring (mac-namestring path)))
      (rlet ((fsspec :fsspec))
        (with-pstrs ((name namestring))
          (#_fsmakefsspec -1 -1 name fsspec))
	(#_NewAlias (%null-ptr) fsspec alias))
      (with-dereferenced-handles ((aliasptr (%get-ptr alias)))
        (#_AECreatedesc #$typeAlias aliasptr (rref aliasptr aliasrecord.aliassize)  the-desc)
        (#_DisposHandle :check-error (%get-ptr alias))
        ))
  the-desc))

(defun create-finder-open-selection (the-desc the-target paths &rest create-keywords)
  (apply 'create-appleevent the-desc $kAEFinderEvents $kAEOpenSelection the-target
         create-keywords)
  (let ((directory (namestring (make-pathname :directory (pathname-directory (car paths))))))
    (with-aedescs (directory-alias rest-aliases)
      (create-alias-record directory-alias  directory)
      (create-alias-list rest-aliases paths)
      (ae-error (#_AEPutParamDesc the-desc #$keyDirectObject directory-alias))
      (ae-error (#_AEPutParamDesc the-desc $keySelection rest-aliases)))))

(defun send-open-to-maclayers ()
  (with-aedescs (appleevent reply target)
    (create-named-process-target target "Finder")
    (create-finder-open-selection appleevent target 
                                  '("applications:communication:dialscript:runlayers"))
    (send-appleevent appleevent reply :reply-mode :wait-reply)
    (ae-get-parameter-char reply #$keyDirectObject nil)))

Anyways, when I run send-open-to-maclayers, I go into the finder, but
then lisp gets the error

> Error: Data in an AppleEvent could not be read. (-1702)
> While executing: send-appleevent

I've written this stuff by analogy to the applevent-toolkit code. I
may be very confused...

Any ideas? Other ways to launch an application?

-alan

ps.

The doc from the ae event registry follows: 

Open Selection: open the specified icons

An Open Selection Apple event asks the Finder to open one or more
icons in the same folder. Sending this Apple event has the same effect
as (1) selecting one or more icons in the same folder and then (2)
choosing Open from the File menu of the Finder.

Event Class kAEFinderEvents
Event ID    kAEOpenSelection

Parameters

keyDirectObject 

Description:An alias record that specifies a folder.  All of the icons
to be opened must be in this folder. This alias record must contain a
full alias, not a minimal alias.Note: If an iconsuch as a disk iconis
not contained in a folder, the keyDirectObject parameter must be an
alias for the icon itself.

Descriptor Type:typeAlias

Required or Optional?Required


keySelection 

Description:A list of alias records. (The items in this list--descriptor
records of type typeAlias--can contain either complete or minimal
aliases.) These alias records specify the icons to be opened.

Descriptor Type:typeAEList

Required or Optional?Required