Help with AppleEvents
Paul Stary
paul at starytech.com
Mon Nov 17 02:37:23 EST 2003
Here is the definitive workaround for sending AppleEvents to a remote
Macintosh.
The "send to program" feature of Revolution DOES NOT WORK! So don't
waste a day as I did trying. Perhaps RunRev should either fix the
problem or modify the dictionary to clarify the problem and provide
the workaround below.
In the example below, I have hard coded the application and machine
into the "sendAE" handler, but this could be feed into the handler
via two additional parameters. You can get the application name and
machine name by executing...
do "choose application" as AppleScript
Assume you have the following script in a button whose function is to
send a doScript AppleEvent, passing "your data" to an application
named "Target Program" on a remote machine named "Remote Mac".
on mouseUp
sendAE "misc", "dosc", "your data"
end mouseUp
Then the following script resides in the button's card or stack script:
on sendAE pAEclass, pAEid, pAEdata
put "application" && quote & "Target Program" & quote && "of machine" && \
quote & "Remote Mac" & quote into tProgram
put "tell" && tProgram & return into tAScript
put numToChar(199) & "event" && pAEclass & pAEid \
& numToChar(200) && quote & pAEdata & quote && "& return" & \
return after tAScript
put "end tell" & return after tAScript
do tAScript as AppleScript
return the result
end sendAE
This exactly follows the example put forth by Jan Schenkel except for
the addition of quote constants around the data portion, i.e., quote
& pAEdata & quote (see original text from Jan below for more details).
Big thanks to Jan and others who contributed to this very solid
workaround and saved the day for me.
Paul Stary
At 6:47 AM -0700 11/15/03, Rob Cozens quoted Jan Schenkel:
>It took me a while to test various combinations, but
>here are my conclusions for RunRev 1.1.1:
>
>1) 'send to program ... with reply'
>- problem: results in an error upon execution
>- solution: omit the optional 'with result' clause
>- note: 'without reply' doesn't result in an error
>
>2) 'answer program' doesn't work in MC/RR
>- known issue, due to limitations in the Carbon API
>- solution: do "choose application" as AppleScript
>- note: would still be handy if it were included
>
>2) 'send to program' on the same machine works, but
>'send to program' where the program is on a remote
>machine doesn't work
>- i tried it on a variation of machines, but the error
>is always "no such program"
>- solution: AppleScript to the rescue ! there is a
>little-known method of sending 'raw' apple events from
>within AppleScript, so the trick is to wrap it as an
>AppleScript of the form:
> tell application "Foo" of machine "Bar"
> <<event rIPCrIPL>> "Hello there!" & return
> end tell
>in which << and >> are to be replacd by their
>single-char equivalents for MacOS (ASCII- 199 and
>200).
>So here's a sample code that works :
> on SelectProgramAndSendAE pAEclass, pAEid, pAEdata
> do "choose application" as AppleScript
> put the result into tResult
> if tResult is "execution error" then
> return "Cancel"
> else put tResult into tProgram
> -- looks like: application "Foo" of machine "Bar"
> put "tell" && tProgram & return into tAScript
> put numToChar(199) & "event" && pAEclass & pAEid \
> & numToChar(200) && pAEdata && "& return" & \
> return after tAScript
> put "end tell" & return after tAScript
> do tAScript as AppleScript
> return the result
> end SelectProgramAndSendAE
>- note: this was very messy to debug, and I crashed my
>iBook several times before I got it right.
>- warning: if the application on the other side is a
>RunRev-built one, make sure you 'pass' any AppleEvent
>message that you don't handle with a 'reply', or you
>risk freezing up the client-side computer.
>
>I also tested the same code with pre-beta 4, with
>equal results. So in conclusion: yes, this is a
>definite bug, and I don't like the workaround, but at
>least there is one.
>
>Scott or Kevin, could this be fixed for MetaCard 2.5 /
>RunRev 2.0?
>
>Jan Schenkel.
--
Paul Stary
Audio-Video Engineering
Voice Mail: (949) 646-8877
Fax: (949) 515-3640
More information about the use-livecode
mailing list