Re: adding to a list selected from a list of lists
Re: adding to a list selected from a list of lists
- Subject: Re: adding to a list selected from a list of lists
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 19 Feb 2002 08:32:11 -0800
On 2/19/02 2:39 AM, "paul withey" <email@hidden> wrote:
>
hi all,
>
i am a newbie scriptor playing around with mainly with itunes and
>
was wondering i anyone can help with this small problem i am having with
>
a script i am working on...
>
>
I would like a user to be able to add a text string to one of a group of
>
existing lists and thought of something along these lines would work...
>
>
list1 = {"1","2","3"}
>
list2 = {"3","4","5"]
>
the_lists = {"list1","list2"}
OK. Stop here. You're going to need to know the most basic things about
AppleScript syntax before you can do anything with it. First of all,
AppleScript's "English-like" language means that, probably unlike almost
every other programming language out there, you only use the "=" sign as a
statement to _state_ that something (already) is equal to something else,
just as you do in English, arithmetic, or algebra. And that can be tested to
be true or false. You don't use "=" to set some new variable to be equal to
something else. For that, you use the term "set to". Thus, what you want to
do here is
set list1 to {"1", "2", "3"}
set list2 to {"3", "4", "5"}
set the_lists to {"list1", "list2"}
You should not put "list1", "list2" into quotes in the third line if in fact
you're trying to make a list consisting of the first two lists. You should
do
set the_lists to {list1, list2}
But I'm trying to work out what choice you really want to present to the
user here.
>
>
display dialog " what would you like to add ?" default answer ""
>
copy the text returned of the result as string to end of (choose from
>
list the_lists with prompt "where would you like to add the slice ?")
>
>
when run, with the user entering "test" and selecting list2 rather than
>
resulting in list2 = {"3","4","5","test"} as required,
>
the result is {"list2","test"}
'choose from list' only works as a lists of strings, not a list of lists. If
you say
choose from list the_lists with prompt "where would you like to add the
slice ?"
and you've defined the_lists as {"list1", "list2"}, the user will simply be
asked to choose one of those two named lists without knowing what the actual
lists contain. Is that what you want? If so, it's still your job to add
their answer into the actual list chosen, not to the string "name" of it.
Your presentation is quite convoluted. Let's work backwards:
choose from list the_lists with prompt "where would you like to add the
slice ?"
will give the result, say
{"list2"}
another list, if the user has chosen "list2".
display dialog " what would you like to add ?" default answer ""
copy the text returned of the result as string to {"list2"}
will add the user's suggestion "test" as a new item to the end of this list:
{"list2", "test"}
>
>
where did it all go pete tong ?
It just did exactly what you asked it to do.
I think this must be what you actually want. Results are given inline as we
go along with -->
set list1 to {"1", "2", "3"}
set list2 to {"3", "4", "5"}
set the_lists to {"list1", "list2"}
set theChoice to choose from list the_lists with prompt "Where would you
like to add the slice ?"
--> {"list2"}
--now you must specify what you actually want done
if theChoice is false then
return -- cancel button
else if theChoice = {"list1"} then
set theChoice to list1
else
set theChoice to list2
end if
--> {"3", "4", "5"}
display dialog "What would you like to add ?" default answer ""
--> "test"
copy the text returned of the result to the end of theChoice
-->"test"
theChoice
{"3", "4", "5", "test"}
You can learn about AppleScript syntax from tutorials at the AppleScript
website, from modules you can download there, from links to Bill Briggs'
tutorials there, from the AppleScript Language guide you can download there
free, from the O'Reilly book "AppleScript in a Nutshell", available
everywhere, and from an older book "Danny Goodman's AppleScript Hanbook",
available from amazon.com.
>
>
Also, as an aside, does anyone know of a good site with examples of
>
scripts for osX's Mail application ?
>
No, sorry. Checkout <
http://macscripter.net> - Script Builders link and
<
http://www.applescriptcentral.com/>
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.