Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

String error

Hey, I'm busy working on a small list script where you can either add to the list or view it, and the items entered are saved across runs. The script I have so far is...

property completedList : {}

display dialog "What would you like to do?" buttons {"View List", "Add"} default button 2

if result = {button returned:"Add"} then

A()

else


display dialogcompletedListbuttons {"Add"} default button 1

if result = {button returned:"Add"} then

A()

end if

end if

on A()

set x to text returned of (display dialog "What would you like to add?" default answer "" buttons {"Add"} default button 1)

set end of completedList to x

B()

end A

on B()

display dialog "What would you like to do?" buttons {"View List", "Add"} default button 2

if result = {button returned:"Add"} then

A()

else


display dialogcompletedListbuttons {"Add"} default button 1

if result = {button returned:"Add"} then

A()

end if

end if

end B


However I am getting this error:

error "Can’t make {\"Thing1\", \"thing2\"} into type string."


How do I fix this, and is there any better way to write the script I have?

Also, would it be possible to put theList into a choose from list, but make it so that when more than one item is entered (separated by a comma) that item goes to the next line on the list. Then could those items be sorted into alphabetical order, or is this asking too much of applescript?

Thanks

Posted on Apr 24, 2011 10:33 PM

Reply
4 replies

Apr 25, 2011 6:07 AM in response to SomeoneRandom

You're getting the error because display dialog takes a string as its argument and you're sending it a list. You can take the elements in the list and concatenate them into one long string, you could show each element separately in a loop, there are many different ways depending on the real use of the list.


One quit and dirty method is to use choose from list in place of display dialog even though you're not asking the user to choose one of the list items. Just ignore the return value.


I don't really follow what you are asking at the end of your post perhaps you could clarify it.

Apr 25, 2011 7:39 AM in response to Frank Caggiano

Thanks, using a list instead worked perfectly.

The only thing I'd still like to know is, if you press add and type in more than 1 item. Say for example you add 'thing1, thing2'. Is it possible for the script to identify that there is a comma between the two things, and put the second thing on a new line in the list?


Oh and also, how do you change the names of the buttons in a list?

Just thought of something else, sorry for having so many questions! If I view the list while its empty, it comes up with an error. Can I make it so that it just shows a list with nothing in it?

Thanks


Edit: One last thing, how can I make a reset button that will clear all the items currently in the list?

If you don't have time/feel like answering all these additional questions, just say and I'll make a new thread 😊

Apr 25, 2011 11:27 AM in response to SomeoneRandom

Thanks, using a list instead worked perfectly.

I'm guessing you meant string there?


The only thing I'd still like to know is, if you press add and type in more than 1 item. Say for example you add 'thing1, thing2'. Is it possible for the script to identify that there is a comma between the two things, and put the second thing on a new line in the list?

It's a computer, anything is possible 🙂 Are you planning on an individual item in the list being multiple words ie 'thing one' or will they always be one word?

If it will always be one word the easiest thing would be something like:


set x to text returned of (display dialog "What would you like to add?" default answer "" buttons {"Add"} default button 1)

set foo to {}

set text item delimiters to " "

set foo to text items of x

choose from list foo



And just having the items delineated by the space between the words. You could use a comma as the delimiter but you might have to clean up the imput

in that case. Try the above code changing the delimiter from " " to "," to see the difference.


Oh and also, how do you change the names of the buttons in a list?

Not sure what you mean by name of 'buttons in a list'



If I view the list while its empty, it comes up with an error. Can I make it so that it just shows a list with nothing in it?

Put in logic to test if the list is empty before displaying it.


if foo ≠ {} then


choose from listfoo

else


display dialog "Empty"

end if




One last thing, how can I make a reset button that will clear all the items currently in the list?


You really have enough knowledge at this point to figure this one out on your own but to get you going:


You want to set your list to the empty list ie. {} but only when the user says to. So ask the user if they want to reset the list and do it if the answer is yes.

String error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.