Resolved Applescript and lists

Discussion in 'Mac Programming' started by Roadrun3r, Jun 4, 2011.

  1. Roadrun3r, Jun 4, 2011
    Last edited: Jun 5, 2011

    Roadrun3r macrumors newbie

    May 29, 2011
    I'm not even sure if this is possible in applescript, or even applescript studio, but then again I hardly know a thing about either one.
    My goal is to make a script where you can input 4 (or more?) numbers, such as the last four of your phone number, and the script will tell you what words can be made from it. (You know: 2 = abc, 3 = def, 4 = ghi.... like on a phone keypad)
    I would think it would be something like:
    set numTwo to {"a","b","c"}
    set numThree to {"d","e","f"}
    --Set a list for every number--
    display dialog "first number" default answer ""
    set diagresultOne to text returned
    if diagresultOne is "2" then set firstNum to numTwo
    something like that but then somehow have it process what possible words can be made from the 4 letter that were typed in. I'm sure it would have to be really complicated, but are there any applescript pros willing to help a beginner out?
  2. Roadrun3r thread starter macrumors newbie

    May 29, 2011

    An other way that you could maybe do it is using lists. such as selecting a number from a succession of lists, then using that for the letter part. but i dont know. PLEASE HELP MEEE.:confused:
  3. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Are you learning from book? Following an online tutorial? Making up exercises as you go?

    If you're working from a book or tutorial, which one?

    If you're not working from a book or tutorial, then you're already in over your head. I don't think you've thought this through at all. If you have, please describe where you get your list of words.

    I suggest that you get a book or follow an online tutorial, and do only the exercises or samples as instructed. In my opinion, the program you described is far beyond your current skill level. You need solid fundamentals first, and it looks to me like you don't have them.

    Just because an idea is simple to describe doesn't mean it's simple to write a program for.
  4. seepel macrumors 6502


    Dec 22, 2009
    I would definitely attack this from a different direction. Get you list of words first (hopefully you aren't going for the entire dictionary of 4 letter words). Then take the users digits and filter the lists, so for example 1234.

    Filter the list down to only the words that begin with [ a, b, c ], then filter those words where the second letter is [ d, e, f ]. And to map the numbers I would do a simple thing where you have a list of ten lists where the index of the list corresponds to the number so your list would look like

    [ [ ], [a, b, c], [d, e, f], ... ]

    Then you can just get the list of letters by using the index, so 1 -> [a, b, c]

    Sorry for using python/JSON notation, I'm not familiar with Applescript list notation, hopefully it would be fairly similar.
  5. Roadrun3r thread starter macrumors newbie

    May 29, 2011
    Dear chown33,
    No offense intended, but what is the point of having an Applescript editor built right into my computer if I only use it with proven programs? How do you think new program ideas are thought of and made into the real thing? I learned 90% of my applescript vocab on a single webpage. I then used my CREATIVITY to figured out ways to use it in many fun ways.
    You don't have to post on how I should go about in my ways. You never even answered the question or moved the thread along at all.

    Dear seepel,
    Thank you! I would have never thought of using INDEXES. Great idea! Now I know how to do that part, but what about the "filtering." I know you don't usually script in applescript, but any ideas are appreciated.
  6. Red Menace macrumors 6502

    Red Menace

    May 29, 2011
    Littleton, Colorado, USA
    I worked up an example earlier, but chown33 is correct and was just asking some valid questions - the last few topics of yours I have seen deal with fairly basic stuff. In this case, indexing into a simple list of lists will get some characters, but getting all the possible word conversions is not a trivial task (unless your example was just to demonstrate this kind of array usage). For anything more than a few characters, AppleScript probably isn't even a good language to use.

    The following example will get a random group of letters, but you will need to create a dictionary to compare against and do some manipulations (there can be a lot of math involved, as well) to get valid words.

    set letterGroups to {¬
    	{}, ¬
    	{}, ¬
    	{"a", "b", "c"}, ¬
    	{"d", "e", "f"}, ¬
    	{"g", "h", "i"}, ¬
    	{"j", "k", "l"}, ¬
    	{"m", "n", "o"}, ¬
    	{"p", "q", "r", "s"}, ¬
    	{"t", "u", "v"}, ¬
    	{"w", "x", "y", "z"} ¬
    set theWord to ""
    set theNumber to text returned of (display dialog "enter a number:" default answer "2345")
    repeat with aNumber in (characters of theNumber)
    	try -- skip alpha and punctuation characters
    		set aNumber to (aNumber as integer) + 1 -- list starts at zero
    		set theWord to theWord & some item of (get item aNumber of letterGroups)
    	end try
    end repeat
    display dialog "Random word derived from (phone key pad) mapping the number " & (quoted form of theNumber) & ":   " & theWord
  7. Roadrun3r thread starter macrumors newbie

    May 29, 2011

Share This Page