How to fetch a choosen Item from a list?

Hi Folks,

Sometimes the differences between AS and XCode are very frustrating,


set auswahl to choose from list {"1", "2", "3", "4"} with prompt "Select a number"
display dialog auswahl


is working fine in AS but not in AS Studio…

Thanks for any input!

BR

Stefan

Hi Stefan,

There is no difference, but plain AppleScript might be more tolerant about your syntax errors :wink:

choose from list returns a list or boolean false if the user has pressed “Cancel”

set auswahl to choose from list {"1", "2", "3", "4"} with prompt "Select a number"
if auswahl is false then 
-- do some error handling
end
display dialog item 1 of auswahl

Hi Stefan,

thanks for your reply,
but how can I use the selected from list in a variable?

Thanks a lot for your assistance!

Stefan

something like this?

set auswahl to choose from list {"1", "2", "3", "4"} with prompt "Select a number"
if auswahl is false then
	-- do some error handling
end if
set newvar to auswahl
display dialog newvar 

I don’t really understand your question, but this seems to be what you’re getting at.

assign item 1 of auswahl to another variable or do it this way

set auswahl to (choose from list {"1", "2", "3", "4"} with prompt "Select a number") as string
if auswahl is "false" then
	-- do some error handling
end if
display dialog auswahl

Try something like this:

choose from list {"1", "2", "3", "4"} with prompt "Select a number"
tell result
	if it is false then error number -128 -- cancel (or whatever)
	set auswahl to first item
end tell

-- log class of result
display dialog auswahl

Why create a new variable for this?

This will coerce any Unicode text (well, sort of) or numbers to string. (Check the class of result in my script.)

yeah, i knew that - i was just doing what he seemed to be asking. I guess I could have given him the simpler solution.