FROM REV to APPLESCRIPT

Terry Vogelaar terry at discovery.nl
Mon Aug 12 02:59:01 EDT 2002


Mr Tea alias Nick wrote:
> As an AppleScript enthusiast, I'm keen to find out more about integrating
> RunRev Stacks with AppleScripts. I'm still fumbling for the doorbell with
> Revolution, though, and as a consequence my attempts to understand the
> script that Terry posted have led to nausea, searing pains in my frontal
> lobe and an urgent need to lie down.
> 
> If there's any further information or examples out there (or in the
> documentation) about integrating AS with RR, could someone please point me
> to it?
> 
> My main interest at this stage would be in using RunRev as a front end that
> can launch/run applescripts and pass information entered by the user to
> them.

Then Ken, a son of thunder, wrote:
> You could take a look at the Tips page on my site... there are a couple of
> AppleScript examples there:
> 
> http://www.sonsothunder.com/devres/revolution/revolution.htm

I am sorry, Nick Tea, for the instand headache I caused without knowing. And
I have to warn you that this very same sample and therefore that same
brain-torture will strike you when visiting Ken Thunder's great website. The
version on Ken's site (which I posted, so it might very well be my fault),
contained a typo and because copied it from that site, the version posted on
this list contained the same error (Ken, could you modify the site so this
error is corrected? The right version is at the bottom of this e-mail).
Also, I will explain my script a bit. (The people who follow this list for a
longer time will puke of it, because I post it again. Sorry for that).

A very little known AppleScript feature is that you can call AS-functions
from another file. Suppose there is a file "MacHD:otherFile" which contain a
function named "executeThat". Then you can write:
   set theScript to load script (alias "MacHD:otherFile")
   tell theScript to executeThat("param",123)
The only thing "AppleScriptFunction" does is produce these two lines
correctly and execute them as AppleScript.

The thing with the paramcount can be confusing as well. In Transcript, all
parameters not named after the name of the function itself (in this case 2),
are stored in param(3), param(4) etc. So the script puts them behind the
first part of the variable ASfunc. The strings between quotes, the numbers
without quotes.

Then there is a part I don't understand myself; there is no explicit value
returned by this function. And yet it works and it returns the same thing
the function in the "otherFile" returns. Why? I don't know, but when I
wanted to implement that, it already seemed to be working.

So here is the bug-free, headache-proof working version of the script:
You call it by using:

get AppleScriptFunction("executeThat", "MacHD:otherFile", "param", 123)

and in the stack-script you put:

function AppleScriptFunction aFun, aFile
  put "set theScript to load script (alias "&quote&aFile&quote&")"&return& \
      "tell theScript to "&aFun&"(" into ASfunc
  if paramcount() > 2 then
    repeat with e = 3 to paramcount()
      put param(e) into f
      if param(e) is a number then
        put f & "," after ASfunc
      else
        put quote & f & quote & "," after ASfunc
      end if
    end repeat
    put ")" into last char of ASfunc
  else
    put ")" after ASfunc
  end if
  do ASfunc as applescript
end AppleScriptFunction

Terry





More information about the Use-livecode mailing list