AppleScript functions made easy
yves COPPE
yvescoppe at skynet.be
Thu Feb 7 06:26:01 EST 2002
>In HyperCard I had a stack with a lot of AppleScript functions. Because RR
>treads AppleScript differently, I tried to make a function which may come in
>handy for others as well.
>
>The basic idea is that you store the AS-functions in a separate file; a
>normal AppleScript-file. No custom props or fields needed, so you don't have
>to work with a copy of the script, but you can work with the original, which
>saves time when the AppleScript function is still in development.
>
>Then you must know the path and the name of the function in the file. You
>call it with:
>
>get AppleScriptFunction("nameOfFunction", "path:to:file", 1, 2, "three",
>"four")
>
>Mind that on Mac OS classic you need to use colons in the path (2nd param),
>while on Mac OS X you must use slashes.
>
>Then in the stack-script you can put:
>
>function AppleScriptFunction aFun, aFile
> put "set theScript to load script (alias ""e&aFile"e&")"&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
> end if
> put ")" into last char of ASfunc
> do ASfunc as applescript
>end AppleScriptFunction
>
>Now you can call any function with any number of parameters. The value that
>is returned by the AppleScript-function is returned by "AppleScriptFunction"
>as well.
>
>Terry
>
Thank you, really very useful !
--
Greetings.
Yves COPPE
Email : yvescoppe at skynet.be
More information about the use-livecode
mailing list