Re: Passing calls to an AS app via shell?
Re: Passing calls to an AS app via shell?
- Subject: Re: Passing calls to an AS app via shell?
- From: Andrew Oliver <email@hidden>
- Date: Fri, 08 Oct 2004 09:39:50 -0700
On 10/8/04 3:13 AM, "Johnny AppleScript" <email@hidden> wrote:
[snip]
>
> Now, I want to know if there¹s a way to pass the string (hello world) directly
> to a running applet, preferably without the use of osascript.
>
> If I have an applet, say, myRunningApp.app¹, which is always running in the
> background, I think I can pass a variable to it from osascript, and then have
> it act on it, correct? What I really want to do is avoid the (albeit short)
> delay created by use of osascript commands. Does anyone know of a way for an
> idling Applet to ³listen² for calls from the system or shell, and act on them,
> without writing data to a text file?
>
> Short of that, I think I can figure out the osascript method, but if anyone
> has any samples, I¹d appreciate it.
>
> TIA JA (getting in deeper than he¹d like with this one)
Now, to answer the specific question rather than get bogged down in the
discussion of '~/Temporary Items/'...
The short answer is no.
>From a shell perspective there are two ways of launching an AppleScript.
Either save the script as an application or use osascript.
The only parameters AppleScript applications accept/understand are files
dropped on the script icon which are passed to the 'open' handler.
For some obscure reason that isn't clear to me, files passed in on the
command line do not count - only files literally dragged and dropped onto
the script icon apply (Chris, can this get fixed?)
As for osascript, you can use this to launch an AppleScript, either as a
compiled script or as a text string that's passed through osacompile before
execution. However, as `man osascript' says:
BUGS
osascript does not yet provide any way to pass arguments to the script.
At least it is classed as a bug, but there's no indication this one will
ever get fixed (can you tell I feel strongly about this issue? ;) )
So in answer to your question: no, there is no way to pass arbitrary
parameters directly to your script. The 'best' solution available involves
writing your parameters to a known file location and having your script read
that file when its launched. A somewhat inefficient but workable solution in
most cases.
The only other solution I've found is to load the script via osascript and
call a handler in that script such as (watch for line breaks):
> osascript -e 'set myscript to load script file "path:to:your.scpt"' -e 'tell
myscript to foo ( "bar" ) '
Which calls the 'foo' handler in your script and passes the "bar" parameter
to it. This works fairly well with a few caveats - first there's the
overhead of loading the entire script, secondly your script cannot have any
user interaction (a limitation of osascript which you can overcome via
sudo), thirdly it's inelegant and a PITA to write.
Neither of these solutions, though, really meet your criteria of having your
background script 'listen' for commands passed directly to it
Andrew
:)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden