help with exiting a simple script

The script below does not exit unless it finishes reading the entire text. I want to listen the entire text but I want the script to exit.

tell application "Skim" to set thetext to text of current page of document 1
say thetext

One idea would be to tell another application to say it, and use ignoring application responses. It has to be a different application because ignoring application reponses does not work for intra-process OSAX calls, but does for inter-process ones). But intentionally inter-process OSAX calls are probably not the best idea, since they seem to be incompatible with Snow Leopard due to Scripting Addition Security changes.

Another way is to use the shell version of say and run it “in the background”.

do shell script "say " & (quoted form of someText) & " &> /dev/null &"

Hi chrys,
Thanks for the reply.
Fortunately, in this case, shell is able to run the command to speak test. So, if I am not using inter-process OSAX, what to do when shell can’t do it? Is there no alternative, currently?

It depends on why the shell version of say would not work for your purpose. If it is because the shell version does not support some feature that the AppleScript version does (like the speech recognition integration), then you might be also to used the “˜Say’ Server” approach below. If it is because the text is so long that it will not fit into a single command line, then you could instead write it to a file (with an AppleScript write) and use say -f <path to text file>.

I am not aware of any other ready-made interfaces to the speech generation code, but APIs are probably available from C and Objective C. Also, you might be able to put just the AppleScript say into a hander in an AppleScript program saved as an application bundle. Then you could use a regular interprocess command to invoke the handler:

-- Saved as a stay-open application bunld named "˜Say' Server.app"
on saySomething(someText)
	say someText
end saySomething
ignoring application responses
	tell application "˜Say' Server" to saySomething("that takes the computer a long time to read aloud")
end ignoring
display dialog "AppleScript has resumed"

This approach also gives you an handy application icon in the dock that you can Quit/Force Quit if you want to abort the speech. You can abort the command line one too, but you have to find/know the PID and kill it.