Re: Passing arguments to an AppleScript?
Re: Passing arguments to an AppleScript?
- Subject: Re: Passing arguments to an AppleScript?
- From: matt neuburg <email@hidden>
- Date: Sat, 27 Sep 2003 06:19:07 -0700
On Fri, 26 Sep 2003 12:30:12 -0500, Adam Knight
<email@hidden> said:
>
So I've looked into NSAppleScript and have it working for
>
a simple script I need to use to control a second program
>
(not mine). What I really need is a way to set variables
>
in the script based on preferences in my own program.
>
>
There's a ton of documentation on how to make a program
>
scriptable, but I can't find much on actually using
>
AppleScript within a program. At this point I'm tempted
>
to load the script from a text file, replace some strings,
>
then compile and run it. Seems hackish since AppleScript
>
supports arguments already (right?).
>
>
Of course, by posting I'll figure it out in a few minutes,
>
but I'd appreciate any pointers anyway. :)
This has been dealt with many times in the past here, so the main
pointer is to the archives.
It is not quite correct to say that "AppleScript supports
arguments already". Your point of entry is the run handler, which
typically doesn't have arguments (in fact, it is typically
implicit). One solution is to take advantage of the "run script"
scripting addition, which is the only way you *can* pass
parameters to a run handler (in that case you'll need an explicit
run handler, obviously). Another is to use "load script" and use
globals to hook free variables in the loaded script to values in
the script that loads them.
So, for example, the way my app does what you're describing is
this: it constructs at run time a string which is a script that
creates some globals, sets them to the values from the prefs, and
calls "load script" on the real script; it then compiles and runs
this string using NSAppleScript. The real script is sitting
pre-compiled somewhere on disk as a separate entity, and uses
free variable names that match those globals. m.
--------
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.