Applescript error in type letter for letter script

Discussion in 'Mac Programming' started by NeeLonMac, Dec 11, 2010.

  1. NeeLonMac macrumors newbie

    Joined:
    Oct 6, 2010
    #1
    Dear people,

    I am lazy. I want to touch my keyboard and mouse as few as possible.
    Therefor, I created a script that can type letters for me, so I can Google with only voice commands.

    Too bad I am a too big Applescript Noob for it won't work.

    I based it on the number typing script on this page.
    But it is slightly different for I want to typ it letter for letter, so I can see if I made a mistake.

    Here's my script, the error is in the interpretText, but I don't get it. Who will help me?

    Thanks in advance!


    Code:
    --set up variables
    property alphaList : {"Alfa", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliett", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", "enter", "stop typing"}
    set theText to ""
    set theInput to ""
    
    --give feedback that we're listening
    say "type"
    
    tell application "SpeechRecognitionServer"
    	repeat until theText is in {"enter", "stop typing"}
    		--listen for input
    		set theText to listen for alphaList
    		--accumulate our input for later processing
    		if theText is not "stop typing" then
    			set theInput to interpretText(theText)
    			tell application "System Events"
    				keystroke (theInput as text)
    			end tell
    		end if
    	end repeat
    end tell
    
    on interpretText(theLetter)
    	local Letter
    	set Letter to ""
    	if theLetter is "Alfa" then
    		set Letter to "a"
    	end if
    	return Letter
    end interpretText
    
    -- , "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliett", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", "enter"
     
  2. NeeLonMac thread starter macrumors newbie

    Joined:
    Oct 6, 2010
    #2
    The solution

    If someone was still looking for this, stop.
    I've found a work around.
    Now you can type your google search words without reaching for your keyboard, or buy expensive voice to text software! ;)

    It's for the reeeeaaaaaaaaallllyyyy lazy people, like me!

    Just save it in your speakable items folder as "begin typing" or something like that. It's based on the NATO alphabet, but that didn't work out at all, so I made some changes. I hope I don't get in trouble for using the F-word in a useful way...
    [EDIT]: I see, it got starrred..

    Code:
    --set up variables
    property alphaList : {"Alfa", "Bravo", "Charlie", "Disk", "Echo", "****", "Golf", "Hotel", "India", "Juliett", "Kilo", "Lima", "Mini", "November", "Otto", "Powned", "Quebec", "Romeo", "Sierra", "Tango", "Unit", "Vendetta", "Whiskey", "X-ray", "Yankee", "Zulu", "white space", "backspace", "stop and go", "stop"}
    set theText to ""
    set theInput to ""
    
    --give feedback that we're listening
    say "type"
    -- 
    tell application "SpeechRecognitionServer"
    	repeat until theText is in {"stop and go", "stop"}
    		--listen for input
    		set theText to listen for alphaList
    		--accumulate our input for later processing
    		if theText is not in {"white space", "backspace", "stop and go", "stop"} then
    			set theInput to the first character of theText
    			tell application "System Events"
    				keystroke (theInput as text)
    			end tell
    		else if theText is "backspace" then
    			tell application "System Events"
    				-- simulate pressing the Backspace/Delete key
    				key code 51
    			end tell
    		else if theText is "white space" then
    			tell application "System Events"
    				keystroke " "
    			end tell
    		else if theText is "stop and go" then
    			tell application "System Events"
    				-- simulate pressing the Enter/Return key
    				key code 36
    			end tell
    		end if
    	end repeat
    end tell
    -- NeeL kicks ass
     
  3. Dalton63841 macrumors 65816

    Dalton63841

    Joined:
    Nov 27, 2010
    Location:
    SEMO, USA
    #3
    LOL seems cool, but I'm pretty sure the word you were looking for was "Foxtrot"... :p

    EDIT: I see thats in the original script. Was that a functional change, or just a comical one?
     
  4. NeeLonMac thread starter macrumors newbie

    Joined:
    Oct 6, 2010
    #4
    Foxtrot just didn't do the trick, I couldn't get him to understand it once.
    The F-word on the other hand, he got it every time, and every time at once!
    So it's functional alright! :D

    I changed some more words that didn't work, now my only problem is, I haven't learned my own alphabet by heart jet, but thats a matter of time!
     

Share This Page