stevejobsfan0123

Q: AppleScriptObjC and multiple threads

Hi again folks,

 

I've read a few old discussions here about having multiple threads going in a Cocoa-AppleScript application, but I didn't find any that I think would work for my particular use case.

 

Here is my situation: I have a method which waits for the user to say a phrase, and then executes another method when it hears the phrase. Here is the code I'm using currently:

 

on listenForQuery()
set query to ""
        try
            tell application "/System/Library/PrivateFrameworks/SpeechObjects.framework/Versions/A/SpeechRecognitionServer.app"
                set query to listen for {"Hello"} giving up after 5
            end tell
        end try
        if query as text is equal to "Hello" then my newQuery_(null)
        performSelector_withObject_afterDelay_("listenForQuery", missing value, 2.0) -- do it again every two seconds
    end listenForQuery

 

The problem is, the program can't do anything else while the Speech Recognition Server is waiting to hear the phrase. I'd like to allocate a separate thread for the above method so it can run with other parts of my program simultaneously. Is this feasible, and if so, how?

Posted on Jun 14, 2016 4:11 PM

Close

Q: AppleScriptObjC and multiple threads

  • All replies
  • Helpful answers