Rev && appleScript

Ben Rubinstein benr at cogapp.com
Tue Jan 13 16:06:52 EST 2009


Timothy Miller wrote:
> When I
> 
> do <container> as "applescript"
> 
> is it possible for applescript to pass a variable or function or 
> something back to rev?
> 
> For instance, just to keep it simple, could I somehow use "the result" 
> from appleScript in a Rev script?

Yes.  If you test "the result" immediately after 'do'ing some applescript, it 
will contain the result the of the applescript - or an error.

So for example
	do "get 2 + 3" as applescript; put the result

is a very slow way to add; while,

	do "get 2 + " as applescript; put the result

will put "compiler error".

> If someone can applescript off the cuff and is feeling generous, I want 
> to use Rev to check if "/applications/firefox.app" is running. 
> Suggestions received gratefully.
> 
> I tried checking the openProcesses, but it doesn't seem to work 
> reliably, and it doesn't work if I launch the application outside of Rev.

There might well be a (better) way of doing this natively - and I suspect that 
failing that you could do it better using the shell command - but to answer 
your question, I happen to have just been looking at a really ancient stack 
dating back to Mac OS 9, which included these functions:

    function theProcesses
      put "set res to" && quote & quote & return \
          & "repeat with p in the processes" & return \
          & " set res to res & (the name of p) & return" & return \
          & "end repeat" & return \
          & "return res" & return \
          into scrpt
      get doAs(scrpt, "Finder")
      replace numtochar(13) with return in it
      delete first char of it -- quote
      delete last char of it -- quote
      return it
    end theProcesses

    function doAs cod, proc
      put "tell application" && quote & proc & quote & return into asCom
      put cod after asCom
      if last char of cod <> return then put return after asCom
      put "end tell" & return after asCom
      do asCom as applescript
      return the result
    end doAs

HTH,

Ben




More information about the use-livecode mailing list