l i v e c o d e

Emulating "Send to Program"
Mac Only Mac Only

AppleScript to the rescue! There is a little-known method of sending 'raw' apple events from within AppleScript, so the trick to doing "send to program" 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.

Posted on 3/16/2003 by Jan Schenkel to the Use-Revolution List   (See the complete post/thread)


 Print this tip

News and Rumors Products Services Developer Resources Contact STS About STS