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

sending applescript events

REGARDING                sending applescript events
Hi there,

We are using some code to call applescript subroutines from 
other applications. We do this by creating an applescript 
appleevent of the subroutine type.

The appleevent takes a list with pascal strings who are 
passed as arguments to the subroutine to be called. 
Everything seems to work but we have one problem with the 
translations from pascal strings to arguments. With the 
following applesscript subroutine in Hypercard:

   on thelength(what)
      stringLength (what)
   end thelength

we get the these results:

(doservice "Hypercard" "thelength" "")  -> 0
(doservice "Hypercard" "thelength" "a") -> 2
(doservice "Hypercard" "thelength" "abcdef") -> 7

Somehow the script arguments gets an extra character (in the 
first position). We think the extra character correspond 
(perhaps) to the count-byte of the pascal string. But how 
does it get in. Can somebody explain this behaviour?

Her is the code we use:

(defun create-subcall (the-desc the-target the-list subroutine arglist &rest
  (declare (dynamic-extent create-keywords))
  (apply 'create-appleevent the-desc :|ascr| :|psbr| the-target
  (ae-error (#_AECreateList (%null-ptr) 0 nil the-list))
  (dolist (arg arglist)
    (ae-error (#_AEPutPtr the-list 0 #$typeChar arg
               (1+ (length (%get-string arg))))))
  (ae-error (#_AEPutParamDesc the-desc #$keyDirectObject the-list))
  (ccl::ae-put-parameter-char the-desc :|snam| subroutine))

(defun doService (app subroutine &optional arg1 arg2 arg3 arg4 arg5)
  (let (temp) 
    (with-pstrs ((Parg1 (ensure-string arg1))
                 (Parg2 (ensure-string arg2))
                 (Parg3 (ensure-string arg3))
                 (Parg4 (ensure-string arg4))
                 (Parg5 (ensure-string arg5)))
      (with-aedescs (appleevent reply target lijst)
        (create-named-process-target target app)
        (when arg5 (push Parg5 temp))
        (when arg4 (push Parg4 temp))
        (when arg3 (push Parg3 temp))
        (when arg2 (push Parg2 temp))
        (when arg1 (push Parg1 temp))
        (create-subcall appleevent target lijst subroutine temp)
        (send-appleevent appleevent reply :reply-mode :wait-reply)
        (ccl::ae-get-parameter-char reply #$keyDirectObject nil)))))

(defun ensure-string (obj)
  (if obj
    (if (stringp obj)
      (format nil "~A" obj))

Thanks in advance,


P.S. Does anyone know of a mailing list like info.mcl on