views:

63

answers:

2

I want to be able to run an applescript from another applescript, but have it return immediately.

I cannot use "osascript script.scpt &" because osascript does not permit "user interaction" and I want to be able to.

So, I'm looking for the equivalent of: osascript script.scpt & in "run script script.scpt"


EDIT for Clarification:

I have an NSAppleScript object that runs a script - that's fine, but I want to initiate the script and immediately return, continuing with the rest of the Objective C program I'm writing.

Right now, the OBJC program waits until the NSAppleScript event finishes.

A: 

One way to do it is to ensure that the second script is launched as its own application. If the second script is static, just compile it once either with the Script Editor or osacompile and launch it from the first script. If you have to construct the second script on the fly, you could do something hacky like this:

osascript - <<EOF
-- first script ...
do shell script "osacompile -o /tmp/script2.app -e 'display dialog \"Hello, world!\"'; open /tmp/script2.app"
-- first script continues ...
EOF
Ned Deily
problem is that that launches an icon in the dock. Is there another way around that without manually editing the UIElement item of the plist of a TEMP app?
Andrew J. Freyer
Not that I'm aware of. Perhaps if you described a bit more about what you are trying to do, someone might be able to suggest a better solution.
Ned Deily
edited original post with more information
Andrew J. Freyer
A: 

Probably the easiest thing is to use NSTask to fork osascript. If you can require Mac OS X 10.6, then you could also try using NSAppleScript in a separate thread, but note the limitations (this doesn't automatically make old language components and scripting additions thread-safe).

Nicholas Riley