Having trouble with a simple IF THEN

I know that it is probably something simple that I am missing…so any help from anyone would be appreciated!

I am trying to learn with a simple program, just to make sure that I understand how things work…but I am not getting something right…

My script is

[i]set site to “”
set response to “”
set siteselect to “Choose from Available Sites”
set site to choose from list {“One”, “Two”, “Three”, “Four”} with prompt "Please select the site that you wish to contact: " with title siteselect

if site = “Two” then set response to “yes”
display dialog response[/i]

When I run the script, no matter what I choose from the list, even if I select ‘Two’…response never gets set to ‘yes’.
It seems that I must be formatting my if then statement incorrectly…or I am missing something else.

Hi,

choose from list returns a list, even if only one item is chosen,
or boolean false, if the user presses Cancel


set site to ""
set response to ""
set siteselect to "Choose from Available Sites"
set site to choose from list {"One", "Two", "Three", "Four"} with prompt "Please select the site that you wish to contact: " with title siteselect
if site is false then return
if item 1 of site = "Two" then set response to "yes"
display dialog response

hiya,

You need to coerce the variable site to text for comparison.
Here’s the line to change:

set site to (choose from list {"One", "Two", "Three", "Four"} with prompt "Please select the site that you wish to contact: " with title siteselect) as text

EDIT: StefanK’s works too :wink:

Thanks for the help…it is nice that I can post a question like this a get two answers so quickly.

Coercions from list to text are dependent on AppleScript’s text item delimiters. If you are using choose from list without multiple selections allowed (which is the default), and you don’t have a need for a list, then simply get the first item of the list.

StefanK’s answer is good, but here a few alternatives:

set site to choose from list {"One", "Two", "Three", "Four"}
if site is false then error number -128 -- cancel
set site to first item of site

-- Compare text
site = "Two"
set site to choose from list {"One", "Two", "Three", "Four"}
if site is false then error number -128 -- cancel

-- Compare lists
site = {"Two"}
choose from list {"One", "Two", "Three", "Four"}
tell result
	if it is false then error number -128 -- cancel
	set site to first item
end tell

-- Compare text
site = "Two"