Jake3231

Q: Applescript and interface won't run together

I am creating a Cocoa Applescript application, and I have an applescript to make speech recognition server listen for commands to use as input.  I also have a small window that should appear at the top.  When I run the application, the speech recognition window appears and works like it is supposed to.  Sometimes the window I created doesn't show up until I quit the applescript part of the program, or it is gray and unusable until I quit the applescript part.  I want them to run side-by-side.  I am aiming for the speech recognition window appearing like normal, and the other window appearing at the same time (or close to the same time) and both working.

MacBook Pro, OS X Mavericks (10.9)

Posted on Oct 26, 2013 12:57 PM

Close

Q: Applescript and interface won't run together

  • All replies
  • Helpful answers

Previous Page 2 of 4 last Next
  • by red_menace,

    red_menace red_menace Oct 28, 2013 8:15 PM in response to Jake3231
    Level 6 (15,541 points)
    Desktops
    Oct 28, 2013 8:15 PM in response to Jake3231

    Glad you like it.  I've uploaded a slightly modified version (same link) that populates the popup button with all of the commands in the dictionary so that you can test them as they are added.

  • by Jake3231,

    Jake3231 Jake3231 Oct 31, 2013 3:35 PM in response to red_menace
    Level 1 (68 points)
    Oct 31, 2013 3:35 PM in response to red_menace

    You are amazing with applescript and objc.  I could never do that.  Thanks for giving me the basis of code to make my project better!

  • by Jake3231,

    Jake3231 Jake3231 Oct 31, 2013 3:51 PM in response to red_menace
    Level 1 (68 points)
    Oct 31, 2013 3:51 PM in response to red_menace

    I just had one more question, how would a make an applescipt variable universal/global to all handlers?  I tried global some_var, but it did not work...

  • by red_menace,

    red_menace red_menace Oct 31, 2013 4:17 PM in response to Jake3231
    Level 6 (15,541 points)
    Desktops
    Oct 31, 2013 4:17 PM in response to Jake3231

    You can use a property - note that properties in Xcode are not persisitent like they are in regular AppleScript.

  • by Jake3231,

    Jake3231 Jake3231 Nov 2, 2013 7:03 PM in response to red_menace
    Level 1 (68 points)
    Nov 2, 2013 7:03 PM in response to red_menace

    Thanks.  I know I keep saying this (sorry about that), but is it possible to have NSSpeechRecognizer listen for any response, like dictation?

  • by red_menace,

    red_menace red_menace Nov 2, 2013 7:22 PM in response to Jake3231
    Level 6 (15,541 points)
    Desktops
    Nov 2, 2013 7:22 PM in response to Jake3231

    I'm no speech recognition expert, but I don't think so.  NSSpeechRecognizer listens for phrases, which are used to determine commands - this is different from what is used in dictation.  Don't forget that you can change the recognizer commands on the fly.

  • by Jake3231,

    Jake3231 Jake3231 Dec 2, 2013 7:05 PM in response to red_menace
    Level 1 (68 points)
    Dec 2, 2013 7:05 PM in response to red_menace

    That is a good point.  I have been thinking and searching for a while (exactly a month now), and I have found the system dictionary word list.  Couldn't I just create a variable to represent this text file and add "it's NSSpeechrecognition some_var" (or something like that.  I can't remember the exact code at the moment) and make it load that whole text file as a commands.  I already have a script to convert every line into a list item too.  The only problem is that I can't have a handler for every word in the dictionary...  I just want it to be able to hear anything, display it, and pull a command from it.  Ex:"Could you please test for a connection?"  It would find that you said "test for connection" and execute it's handler while displaying the whole input string. Is that possible to do at this point?

  • by red_menace,

    red_menace red_menace Dec 2, 2013 7:56 PM in response to Jake3231
    Level 6 (15,541 points)
    Desktops
    Dec 2, 2013 7:56 PM in response to Jake3231

    The API's in Cocoa are designed for commands.  Converting speech to text is one (not so simple) thing, but natural language processing is much more complex (look at what is involved in Siri, for example) - either way you are looking at using some third party framework(s), a lot of work, and most likely some $$$ for licenses. 

  • by Jake3231,

    Jake3231 Jake3231 Dec 5, 2013 3:08 PM in response to red_menace
    Level 1 (68 points)
    Dec 5, 2013 3:08 PM in response to red_menace

    True...  Well could I have it listen for keywords instead?  I know this is possible in applescript, but I searched around and did not find a way to do it in Obj-C.

  • by red_menace,

    red_menace red_menace Dec 5, 2013 6:54 PM in response to Jake3231
    Level 6 (15,541 points)
    Desktops
    Dec 5, 2013 6:54 PM in response to Jake3231

    NSSpeechRecognizer isn't written for natural language processing, but it does listen for defined words or phrases.  In my example AppleScriptObjC application I turn off the recognizer while processing a command to keep from getting interrupted, but a regular Objective-C application could possibly run multiple threads to continually listen and process at the same time (AppleScript, regular or Xcode, is not multi-threaded) - this kind of thing is out of my skill set, though.

  • by Jake3231,

    Jake3231 Jake3231 Dec 5, 2013 7:10 PM in response to red_menace
    Level 1 (68 points)
    Dec 5, 2013 7:10 PM in response to red_menace

    Thankyou! I will have to think about that.  Thanks for all the help you have provided on this topic.  I have been able to create a cool Siri-like thing with your base project and help.  So again thanks. 

  • by Jake3231,

    Jake3231 Jake3231 Dec 15, 2013 9:21 AM in response to Jake3231
    Level 1 (68 points)
    Dec 15, 2013 9:21 AM in response to Jake3231

    Sorry to keep asking for help, but I have noticed you have a line of code that refers to the command list.plist. 

    "set theFile to Cocoa's NSBundle's mainBundle's pathForResource:"Command List" ofType:"plist""

    Is there a way to refet to the .app application?

  • by red_menace,

    red_menace red_menace Dec 15, 2013 9:44 AM in response to Jake3231
    Level 6 (15,541 points)
    Desktops
    Dec 15, 2013 9:44 AM in response to Jake3231

    There are other methods in the NSBundle class to get various paths, for example:

    current application's NSBundle's mainBundle's bundlePath()

     

    Note that I usually use a shortcut for "current application" (in this case the property "Cocoa") to try to keep statements from getting too long (they still wind up being long, but it helps a bit).

  • by Jake3231,

    Jake3231 Jake3231 Dec 15, 2013 3:58 PM in response to red_menace
    Level 1 (68 points)
    Dec 15, 2013 3:58 PM in response to red_menace

    I'll try using the code you suggested, but if I'm understanding what your saying, I could type "set som_var to current application"?  Thanks!

  • by red_menace,

    red_menace red_menace Dec 15, 2013 4:38 PM in response to Jake3231
    Level 6 (15,541 points)
    Desktops
    Dec 15, 2013 4:38 PM in response to Jake3231

    The various Cocoa classes and constants are defined in the Cocoa-Applet wrapper, so to use a class without an instance object you need to target the current application so that the runtime knows what you are talking about.  Some of the statements can get a bit long, especially if they use constants or nested methods, so a shortcut can be used to try to keep the verbosity down - statements can still get a bit wordy, but it helps a little.

     

    The previous statement would normally be done by using something like:

    set appPath to current application's NSBundle's mainBundle's bundlePath()

     

    While the slightly shorter version (which I use in my example project) would be something like:

    property Cocoa : current application -- shortcut property defined once with other script/class properties
    
    set appPath to Cocoa's NSBundle's mainBundle's bundlePath()
Previous Page 2 of 4 last Next