views:

601

answers:

3

I have the following AppleScript so far:

# List of possible options to control the development environment.
set WhatDoUWantToDoList to {"1", "2", "3", "4"}

set MySites to {"test1", "test2"}

# task selected
set selectedTask to {choose from list WhatDoUWantToDoList with prompt "Pick your task now!!!" without multiple selections allowed}

if selectedTask is equal to {"1"} then
    display dialog selectedTask
else
    # site selected
    set selectedSite to {choose from list MySites with prompt "Pick the site your working on!!!"}

    if (selectedTask is not equal to false and selectedSite is not equal to false) then
        display dialog selectedTask
        display dialog selectedSite
    else
        display dialog "you messed up!"
    end if
end if

I am trying to say if option 1 is selected in list 1 display only the selected task, however, if any other option is selected in list 1 you have to move to the new code block, and must select an option in list 2, if you cancel on list 1 and list 2 you screwed up.

Any ideas on what I am missing here?

+2  A: 

{ } in AppleScript creates a list, so when you set selectedTask, you're putting the results from choose from list into another list. When you try to compare the result to {"1"}, it's actually {{"1"}}, so it isn't equal.

Use parentheses ( ) for grouping instead.

Nicholas Riley
i still can not get it to enter the if block<pre>if selectedTask is equal to {{"1"}} then display dialog selectedTask else</pre>if 1 is selected it should enter that if block for a task and stop, whenever I run it it still runs both parts of the if statement
chris hough
You're fixing the problem in the wrong place. Replace the { } in 'set selectedTask to {choose from list WhatDoUWantToDoList with prompt "Pick your task now!!!" without multiple selections allowed}' with ( ).
Nicholas Riley
A: 

using this code worked: if selectedTask contains "1" then

chris hough
A: 

Choose from list will always return an array because multiple selection is possible. The basic idea is:

set selectedValues to (choose from list {"Value 1", "Value 2"} with prompt "Choose")
if (selectedValues is not false) then
    set selectedValue to item 1 of selectedValues
    display dialog ("You chose " & selectedValue as text)
else
    display dialog ("You did not chose!")
end if
cosmin