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

first Previous Page 3 of 4 last Next
  • by Jake3231,

    Jake3231 Jake3231 Dec 16, 2013 10:28 AM in response to red_menace
    Level 1 (68 points)
    Dec 16, 2013 10:28 AM in response to red_menace

    Thanks!  I think I can use that better. :D Also, I might have asked you, but is there a way to use NSSPeechRecognizer to do dictation or keywords?  I know it is not meant for dictation, but can I tell it to listen for keywords? The tell block applescript will sadly cancel the GUI. As we know.

  • by red_menace,

    red_menace red_menace Dec 16, 2013 4:11 PM in response to Jake3231
    Level 6 (15,546 points)
    Desktops
    Dec 16, 2013 4:11 PM in response to Jake3231

    The speech recognizer will listen for whatever words or phrases you want it to.  For something like this, you don't neccessarily need to use different handlers for each word/phrase, the recognized command is passed to the speechRecognizer:didRecognizeCommand: delegate method so you can do whatever you want with it.

  • by Jake3231,

    Jake3231 Jake3231 Dec 16, 2013 4:21 PM in response to red_menace
    Level 1 (68 points)
    Dec 16, 2013 4:21 PM in response to red_menace

    So I can make it listen for anything? I don't have to have deffined commands?

  • by red_menace,

    red_menace red_menace Dec 16, 2013 5:35 PM in response to Jake3231
    Level 6 (15,546 points)
    Desktops
    Dec 16, 2013 5:35 PM in response to Jake3231

    You do need to tell the recognizer what to listen for.  In my example project, I give it the list of phrases to listen for with the setCommands: method, and when one of the phrases is recognized the speechRecognizer:didRecognizeCommand: delegate method is called with the command that was recognized.  In my example project I have the command call a handler that has been assigned to it, but you can do whatever you want with the command.

  • by Jake3231,

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

    Thanks! Sorry for all the questions, but you are so good at applescript.  I was also wondering if there was a way that I could have a window open through applescript.  For example, set a property to the window I want to open, then say "some_window's orderOut".  I don't know the correct syntax, but that is what I might expect, though that code didn't work.  I just wanted to open a window without GUI scripting, but I am fine using it if I have to.  Also, Merry Christmas!

  • by red_menace,

    red_menace red_menace Dec 22, 2013 4:19 PM in response to Jake3231
    Level 6 (15,546 points)
    Desktops
    Dec 22, 2013 4:19 PM in response to Jake3231

    There are a few differences depending on how the particular window is used (e.g. a sheet), but yes, you can connect a window to an outlet property, then use various NSWindow methods to orderOut, orderFront, makeKeyAndOrderFront, etc, for example:

    someWindow's orderFront:me

     

    Make sure that the window doesn't get released when it is closed (an Interface Builder setting), or it will go away.

  • by Jake3231,

    Jake3231 Jake3231 Dec 25, 2013 8:17 AM in response to red_menace
    Level 1 (68 points)
    Dec 25, 2013 8:17 AM in response to red_menace

    Thank you! Thanks for all the help you have provided me.  I might ask, if I were to connect this project to an Apple Developer ID, would I have to change the code that came in the project that looked something like this, "com.apple.red~menace...."  Also, Merry Christmas!

  • by red_menace,

    red_menace red_menace Dec 25, 2013 8:45 AM in response to Jake3231
    Level 6 (15,546 points)
    Desktops
    Dec 25, 2013 8:45 AM in response to Jake3231

    Yes, if you started out with my example project you should go through all of the files and Info.plist, using your own bundle identifier and copyright information.  When creating a new project, Xcode will use your default settings.

  • by Jake3231,

    Jake3231 Jake3231 Jan 26, 2014 5:47 PM in response to red_menace
    Level 1 (68 points)
    Jan 26, 2014 5:47 PM in response to red_menace

    Thanks!  Sorry for replaying so late.  I had a quick problem I ran into while working on this.  I was wondering if there was a way to have NSSpeechSynthesizer to use a certian voice?  If it can't, is there a way to change the system voice without using GUI scripting?

  • by red_menace,

    red_menace red_menace Jan 26, 2014 6:21 PM in response to Jake3231
    Level 6 (15,546 points)
    Desktops
    Jan 26, 2014 6:21 PM in response to Jake3231

    You have to remember that pretty much anything that an application does is built on various Cocoa frameworks (that AppleScriptObjC can usually access) - the NSSpeechSynthesizer class is what provides methods to get and set the voices and various speech parameters.  I even have an example project that uses it, if you want to check it out - my Sliders project (it uses sliders to play with some of the synthesizer properties) can be downloaded here.

  • by Jake3231,

    Jake3231 Jake3231 Jan 28, 2014 5:06 PM in response to red_menace
    Level 1 (68 points)
    Jan 28, 2014 5:06 PM in response to red_menace

    Thanks!  I am trying to use that script.  I had one question.  There was a voice that I wanted to include with the application.  I thought that I could have Finder duplicate the voice's folder in the application to the system voices folder, then set the voice.  That didn't work...  I tried to copy the text to get the Command List's path, but I couldn't set the type to folder.  Is there any easier way to accomplish this?  I'm sure I am missing something simple to make it find the folder.

  • by red_menace,

    red_menace red_menace Jan 28, 2014 7:01 PM in response to Jake3231
    Level 6 (15,546 points)
    Desktops
    Jan 28, 2014 7:01 PM in response to Jake3231

    As long as the voice is installed in one of the standard locations, it should work - note that you should not mess with anything in the System folder.  Installing a voice in the local or user's Library/Speech/Voices folder (you may need to create the folder stucture) works OK for me.

  • by Jake3231,

    Jake3231 Jake3231 Jan 30, 2014 3:04 PM in response to red_menace
    Level 1 (68 points)
    Jan 30, 2014 3:04 PM in response to red_menace

    Okay thanks! The other problem I had is copying the voice folder.  I couldn't figure out how to refer to a folder in the project resources.  I figured out files though.  Once I do that, I can tell Finder to copy the folder to the user's voices folder.  Also, just to confirm, would a user account save across a login network, like in a school?

  • by Jake3231,

    Jake3231 Jake3231 Feb 14, 2014 2:59 PM in response to red_menace
    Level 1 (68 points)
    Feb 14, 2014 2:59 PM in response to red_menace

    Okay..  I have still had trouble with it.  I changed it to copy to the user's voices folder, but I can't make it work yet.  I keep getting an error saying that "Finder cant set folder "Voices" of folder "Library" of home to folder [somefolder]"  I tried to set it to ""&apppath&"/recources/Samantha.SpeechVoice", but that didn't work.  I wasn't able to find the voice in the application contents, but I'm not sure if that is causing the problem.  Am I doing this right?

  • by red_menace,

    red_menace red_menace Feb 14, 2014 4:17 PM in response to Jake3231
    Level 6 (15,546 points)
    Desktops
    Feb 14, 2014 4:17 PM in response to Jake3231

    There are commands in StandardAdditions that you can use to get paths to standard locations, for example:

        path to voices from user domain # user library

        path to resource "Samantha.SpeechVoice" # application

     

    There are also the Cocoa equivalents, but those can still be used - you would need to post the code you are using to troubleshoot further.

first Previous Page 3 of 4 last Next