Applescript? CORRECTION

Jim Ault JimAultWins at yahoo.com
Tue Mar 28 20:12:52 EST 2006


DON'T USE THE PREVIOUS APPLEEVENT HANDLER
--I included 1 bug ==> "aevtdosc" rather than miscdosc"
--and a dangling comment
FIxed here.

To be clear, Rev 2.2.1 allowed the "do script" to be sent from another
program to Rev and trigger a handler. I used this form.

Then, version 2.5.1 no longer would respond automatically, but required
adding an AppleEvent handler that would trap AppleEvents, then parse the
parameters to find what kind of call and which handler to process.

EXPERIMENT
goal [1] to get it to work simply
goal [2] to see double, triple call results
goal [3] to see 'answer dialog' difficulties

Here is how to call a handler in the current stack script or further along
the message hierarchy
--in Script Editor [goal 1]
tell application "Revolution"
    «event miscdosc» " testHandlerA"
end tell

where 'misc' is appleevent class miscellaneous
'dosc' is do script
' testHandlerA' is the handler name

in Rev (1) make a new main stack
(2) paste the following TWO handlers into the main stack script
(3) switch from pointer mode to browse mode
(4) make sure your new stack is in front.
(5) empty the message box to see the output
(6) for some reason with 2.6.1 in the IDE it was necessary for me to go from
browse mode to pointer mode and back again to get the AS call to work each
time.

--script 1 --
on appleEvent p1, p2, p3
  
  request AppleEvent data
  put cr & p1&& p2 && p3 && it after msg
  
  if p1 & p2 is "aevtquit" then
    if the mode of stack "answer dialog" is not 0 then exit to top -- dialog
on screen
    revCheckQuit
    if the result is "quit" then
      lock messages -- prevent duplicate shutDownRequest
      quit 
    else
      exit appleEvent
    end if
  end if
  if p1&p2 is "aevtodoc" then
    --appleEvent sent when stack is opened from the finder
    request AppleEvent data
    put it into tData
    repeat for each line l in tData
      lock messages
      put (there is a stack l) into tExists
      unlock messages
      if not tExists then answer error "Unable to open stack: stack is
corrupted, check for ~ backup file."
      else go stack l
    end repeat
    exit appleEvent
  end if
  if p1&p2 is "miscdosc" then
    request AppleEvent data
    put it into tData
    try
      --do tData
      send tData to me in 500 milliseconds
    catch errorMsg
      answer error "Unable to execute handler '"&tData&"'..."
      exit appleEvent
    end try
    exit appleEvent
  end if
  
  pass appleEvent
end appleEvent

on testHandlerA
  --answer "You got here via AS  !!!"
  put cr& "You got here via AS  !!!    another fine functionality" after msg
end testHandlerA

on testHandlerB
  --answer "The BBBBB version  !!!" after msg
  put cr& "The B version  !!!    " after msg
end testHandlerB
---------------------------  end copy of code here ------
--CAUTION  this will cause a dialog box to show and point out another
gotcha... the calling Applescript will not complete until Rev completes the
AppleEvent handler.  Therefore, you should use the 'send' command in Rev

as follows :  
send tData to me in 500 milliseconds


EXPERIMENT
Now try adding another event
tell application "Revolution"
    «event miscdosc» "testHandlerA"
    «event miscdosc» "testHandlerB excessData"
    
    set readyFlag to "true"
    «event miscdosc» "testHandlerB " & readyFlag
    
    set story to "A fine sunny day in the garden"
    «event miscdosc» "testHandlerB " & story
    
end tell

EXPERIMENT
Now try using the 'do' line and not the 'send' line
Note the order of execution!!

EXPERIMENT
Now try using answer dialogs with and without 'send'

Thanks to the great work of Ken Ray
Valuable links
http://www.sonsothunder.com/devres/revolution/tips/ascr004.htm

http://www.sonsothunder.com/devres/revolution/revolution.htm

Hope you find this useful

Jim Ault
Las Vegas

On 3/28/06 1:56 PM, "Troy Rollins" <troy_lists at rpsystems.net> wrote:

> 
> On Mar 28, 2006, at 4:16 PM, Klaus Major wrote:
> 
>>> 
>>> My Applescript tool (Late Night Software's "Script Debugger X")
>>> claims that Revolution is not scriptable, where it used to show
>>> support for "do script"... any ideas?
>> 
>> I have asked this a couple of times on this list some time ago, but
>> nobody seemed
>> to care or answered my question...
> 
> Ah. So, it isn't just mine.
> 
> Darn.
> 
> --
> Troy
> RPSystems, Ltd.
> http://www.rpsystems.net
> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list