简体   繁体   中英

Return Immediately from “run script” in Applescript

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.

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM