Seting a variable to choices on a list that has a keyword

is ther e any way that a variable can be set to the choices of a list variable which have a keyword in them??

could you give an example, the situation this would be used for?
SC

I’m trying to make an application that has a “database” of Terminal
commands, and you “search” the database w/ a dialog and the new variable
is set to the commands in the database that have the keywords searched
in them. this is what I thought i could use but the syntax is wrong

set theDatabase to {"pico", "vi", "emacs", "cal", "dc", "talk"}
display dialog "Type your search." default answer "" buttons {"Cancel", 
"Search"} default button "Search"
 set theSearch to text returned of the result
set theResult to items of theList that contain text  theSearch
choose from list theResult

help…?

set theDatabase to {"pico", "vi", "emacs", "cal", "dc", "talk"}             --your data
display dialog "Type your search." default answer "" buttons {"Cancel", 
"Search"} default button "Search"                                           --typed in string
 set theSearch to text returned of the result                --set item of the data to thesearch
set theResult to items of theList that contain text  theSearch     --theResult is undefined 
choose from list theResult                                             --trying to get item from the list?

Its seems like your trying to pick an item in the list and have it be a variable? I think this is what you need:


set dataBase to {"pico", "vi", "emacs", "cal", "dc", "talk"}
choose from list dataBase with prompt "Choose option"
set yourVariable to result as text --returns the choice as a variable

Open the “show result” window when you run this, so you see the button name returned with visual confirmation.
SC

i guess ill use that for now, but is there a way to do that, because with a lot of commands it would be very hard to choose

Hi,

You cannot use filters with lists. You need to loop through the list and get the items that match the criteria (contains key). Something like this:

set com_list to {“ahib”, “chid”, “ebyef”, “ghih”}
set k to “hi”
set key_coms to {}
repeat with c in com_list
if c contains k then
set end of key_coms to (contents of c)
end if
end repeat
if key_coms is {} then return
return key_coms

If you have a lot of commands, then you can probably speed it up by referencing the list.

gl,