applescript help (speakable items)

Discussion in 'Mac Programming' started by aesed, Nov 23, 2008.

  1. aesed macrumors newbie

    Joined:
    Nov 23, 2008
    #1
    hi!
    I need help with using speakable items to type letters, one at a time.
    here is my current code:

    tell application "System Events"
    tell application in front to keystroke (ASCII character of 120)
    end tell

    this is of course for character "x"

    when i run this code in script editor, it pastes an x into my code, where my cursor is, but when I try it in Firefox, (using speakable items) it acknowledges that I asked it to do something, but doesn't do anything...:confused::confused:

    edit; i just tried speaking into script editor, and it didnt give me an "x"...
    what would make it work??
     
  2. andmr macrumors member

    Joined:
    Aug 25, 2008
    Location:
    NE Florida
    #2
    Try this...

    tell application "System Events"
    keystroke tab using command down
    keystroke (ASCII character 120)
    end tell

    or...

    tell application "System Events"
    keystroke tab using command down
    keystroke "x"
    end tell

    Notes:

    1) Copy either script and paste into your AppleScript Script Editor. From the Script Editor's File menu, choose Save As > File Format: application, Options unchecked, and place an alias of the saved script app into your Home > Library > Speech > Speakable Items Folder.

    2) Make sure GUI Scripting is enabled. Under System Preferences > Universal Access, "Enable access for assistive devices" should be checked.

    3) Under System Preferences > Speech > Speech Recognition, the Speakable Items radio button should be On. Also, be sure that you're either using a modifier key or listening with a keyword (optional or required) depending on which radio button is selected under Speech > Speech Recognition > Listening Method.

    4) Make sure you're speaking the exact name of the saved script, i.e., if you named the saved script app "x" you would need to say "x" for the spoken command to be recognized.

    Either of the above scripts worked for me. Good luck.
     
  3. aesed thread starter macrumors newbie

    Joined:
    Nov 23, 2008
    #3
    thanks a lot! this page is taking 20 minutes to load on my mac, (and thats not an exaggeration)
    one more question:
    can you just say the name as in the letter "x" or do you have to say the sound as in "ks" (more prominent in "a" as in "ay" or "ah"

    --edit-- i found the answer.. putting a period for the file name does it "x." not "x" yay!

    and what is the command tab for? wouldn't that switch the app? i want to be able to type, not say a letter to switch... pls reply!

    --edit-- ok i found the answer to this one but

    is there any way to make it not have to be an app? cause this way it will be REALLY slow...
     
  4. andmr macrumors member

    Joined:
    Aug 25, 2008
    Location:
    NE Florida
    #4
    Yours is a good question and it led me to further experimenting. While I didn't try every letter of the alphabet, I did test a few letters I thought might pose a potential problem -- "s", "r", "f" and "n." The letter "x" in the initial example, if saved as "x," would type "x" if I spoke it naturally (phonetically: "eks"); but I had a problem with "s" saved as "s" -- Speech Recognition would often get confused and subsequently type "x." Problem solved when I renamed the saved "s" script app to "ess." Likewise "r" saved as "r" had to be renamed "ar" to be recognized. So clearly this is a case when you'll need to find what works for you and rename your script apps phonetically as needed. Good catch!

    Precisely! Using keystroke tab using command down simulates what happens when you hold down your Command key and press Tab. The script needs to switch to the most recently used application, because the current application when the script is running is the saved AppleScript app itself. Therefore, when you're working in Firefox and speak the desired letter, Speakable Items invokes the script app first, and then switches to the last application used (Firefox), and pastes your typed letter into that application. The benefit to using keystroke tab using command down is that the script can be used as a global command -- it will work just as well and without the need for modification in Safari, TextEdit, Mail, etc.
     

Share This Page