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

Re: AppleEvent to a remote a



        Reply to:   RE>AppleEvent to a remote appl
Guess this one should get into the FAQ.

Some tim eago the same question was asked by Eric Shafto and before that by
myself. 
Derek White did send me some code that does that exactly. Below you'll find
what we use now, not the original. It works fine for us but we've had some
problems. For one machine in our
LAN, a quadra 950, the application name was not recognized. Haven't found the
cause of that.

Hope this works for you and thanks again Derek,

Andre Koehorst

;---------------------------------------------------------------------------
(in-package ccl)

(require "Appleevent-Toolkit")
(require "Eval-Server")

(defvar $local-target-name "Local")
(defconstant $your-ppc-type-name "CCL2ep01") ; where CCL2 is your creator type?

(defun parse-zone-str (str &key (default-type-string "PPCToolbox"))
  (let ((start-type (position #\: str))
        (start-zone (position #\@ str)))
    (assert start-zone)
    (values
     (subseq str 0 (or start-type
                       start-zone))
     (if start-type
       (subseq str (1+ start-type) (if start-zone 
                                     start-zone
                                     (length str)))
       default-type-string)
     (subseq str (1+ start-zone) (length str)))))

(defun target-string-target-id (target-string target-id)
  (assert (and (macptrp target-id) ; really needs to be a ptr not a handle
               (stringp target-string)))
  (if (string= target-string $local-target-name)
    (setf (pref target-id :TargetID.location.locationKindSelector)
          #$ppcNoLocation) 
    (multiple-value-bind (object-str type-str zone-str)
                         (parse-zone-str target-string)
      (setf (pref target-id :TargetID.location.locationKindSelector)
            #$ppcNBPLocation)
      (setf (pref target-id :TargetID.location.NBPEntity.ObjStr)
            object-str)
      (when type-str
        (setf (pref target-id :TargetID.location.NBPEntity.TypeStr)
              type-str))
      (setf (pref target-id :TargetID.location.NBPEntity.ZoneStr)
            zone-str))))

(defun app-str-port-info (app-str port-info)
  (assert (and (stringp app-str)
               (macptrp port-info)))
  (setf (pref port-info :PortInfoRec.name.nameScript) #$smRoman)
  (setf (pref port-info :PortInfoRec.name.name) app-str)
  (setf (pref port-info :PortInfoRec.name.PortKindSelector) #$ppcByString)
  (setf (pref port-info :PortInfoRec.name.PortTypeStr) $your-ppc-type-name))
  
(defun choose-AE-target-with-defaults (the-desc 
                                      &key prompt title
                                       default-target-str
                                       default-app-str)
  (rlet ((port-info :PortInfoRec)
         (target-id :TargetID))
    (when (and default-target-str default-app-str)
      (target-string-target-id default-target-str target-ID) ; fill in
target-id
      (app-str-port-info default-app-str port-info))
    (choose-process-dialog 
     :prompt prompt :title title 
     :location-name-record (pref target-id TargetID.location)
     :port-info-record port-info
     :default-specified (and default-target-str default-app-str))
    (setf (pref target-id TargetID.name) (pref port-info PortInfoRec.name))
    (ae-error (#_AECreateDesc #$typeTargetID target-id 
               #.(record-length :TargetID) the-desc))
    the-desc))

(defun remote-send-dosc-with-PPC (command-string machine-name program-name)
  (with-aedescs (appleevent reply target)
    (choose-AE-target-with-defaults target :default-target-str machine-name
:default-app-str program-name)
    (create-dosc appleevent target command-string)
    (send-appleevent appleevent reply :reply-mode :wait-reply)
    (ae-get-parameter-char reply #$keyDirectObject nil)))

(defun create-appleevent-target (the-desc target-str app-str)
  (rlet ((port-info :PortInfoRec)
         (target-id :TargetID))
    (when (and target-str app-str)
      (target-string-target-id target-str target-ID) ; fill in target-id
      (app-str-port-info app-str port-info))
    (setf (pref target-id TargetID.name) (pref port-info PortInfoRec.name))
    (ae-error (#_AECreateDesc #$typeTargetID target-id 
               #.(record-length :TargetID) the-desc))
    the-desc))

(defun remote-send-dosc (command-string machine-name program-name)
  (with-aedescs (appleevent reply target)
    (create-appleevent-target target machine-name program-name)
    (create-dosc appleevent target command-string)
    (send-appleevent appleevent reply :reply-mode :wait-reply)
    (ae-get-parameter-char reply #$keyDirectObject nil)))

#|
(parse-zone-str "Peter@EtherTalk2")
(parse-zone-str "Peter:PPCToolBox@EtherTalk2")

(remote-send-dosc-with-PPC "(format t \"Howdydooditime\")" "Peter@EtherTalk2"
"MCL 2.0")
(remote-send-dosc  "(play-snd \"Wild Eep\")" "John's Mac:PPCToolBox@EtherTalk2"
"MCL 2.0")

(remote-send-dosc  "go card 2" "bram:PPCToolBox@EtherTalk2" "Hypercard")
(remote-send-dosc-with-PPC  "go card 2" "bram:PPCToolBox@EtherTalk2"
"Hypercard")
|#





--------------------------------------
Date: 12/14/93 11:18 PM
To: Andre Koehorst
From: Herve Blanchon
Received: by riks.nl (2.01/GatorMail-Q); 14 Dec 93 23:18:11 U
Received: from sun4nl.UUCP by london with UUCP
          id AA02371; Tue, 14 Dec 93 23:15:48 +0100
Received: from mcsun.eu.net by sun4nl.NL.net with SMTP
	id AA06098 (5.65b/CWI-3.3); Tue, 14 Dec 1993 22:33:02 +0100
Received: from brazil.cambridge.apple.com by mcsun.EU.net with SMTP
	id AA23163 (5.65b/CWI-2.235); Tue, 14 Dec 1993 22:33:00 +0100
Received: from ministry.cambridge.apple.com by brazil.cambridge.apple.com with
SMTP (5.64/25-eef)
	id AA14589; Tue, 14 Dec 93 16:14:10 -0500
	for andre@riks.nl
Received: by cambridge.apple.com (5.64/25-eef)
	id AA13348; Tue, 14 Dec 93 16:18:39 -0500
Received: from brazil.cambridge.apple.com by cambridge.apple.com with SMTP
(5.64/25-eef)
	id AA13335; Tue, 14 Dec 93 16:17:36 -0500
Received: from imag.imag.fr by brazil.cambridge.apple.com with SMTP
(5.64/25-eef)
	id AA14576; Tue, 14 Dec 93 16:11:58 -0500
	for info-mcl@cambridge.apple.com
Received: from isis.imag.fr by imag.imag.fr with SMTP id AA28738
  (5.65c8/IDA-1.4.4 for <info-mcl@cambridge.apple.com>); Tue, 14 Dec 1993
22:12:59 +0100
Received: from [129.88.120.223] (mac_geta-3.imag.fr) by isis.imag.fr with SMTP
id AA05165
  (5.65c8/IDA-1.4.4 for <info-mcl@cambridge.apple.com>); Tue, 14 Dec 1993
22:16:03 +0100
Message-Id: <199312142116.AA05165@isis.imag.fr>
X-Sender: blanchon@isis
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Date: Tue, 14 Dec 1993 22:12:57 +0100
To: info-mcl@cambridge.apple.com
From: Herve.Blanchon@imag.fr (Herve Blanchon)
Subject: AppleEvent to a remote application

Dear MCLers and AppleEvents Hackers,


I want to send an apple event to an application running on an other machine.

I am connected to the machine under the possessor name and can link
application.

I would like to be able to send the AEvent without showing the user the
PPCBrowser.

With the appleevent-toolkit.lisp, I have not been able to perform such a task. 

Any help would be greatly appreciated. Thanks in advance,

Herve.

--
Herve Blanchon  	       	       	       	
GETA, IMAG-campus, BP 53     Tel: +33.7651-4369    Herve.Blanchon@imag.fr
150, rue de la Chimie        Fax: +33.7651-4405
38041 Grenoble Cedex 9