PDA

View Full Version : [Resolved] Applescript and lists




Roadrun3r
Jun 4, 2011, 11:10 AM
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?



Roadrun3r
Jun 4, 2011, 03:18 PM
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:

chown33
Jun 4, 2011, 03:48 PM
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.

seepel
Jun 4, 2011, 06:22 PM
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.

Roadrun3r
Jun 4, 2011, 10:46 PM
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.

Red Menace
Jun 4, 2011, 11:12 PM
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

Roadrun3r
Jun 5, 2011, 06:20 AM
Well thanks everyone!