2009-08-30 44 views
0

我有以下AppleScript至今:AppleScript中的列表值?

# 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 

我想,如果選擇1表1只顯示所選擇的任務被選中的說法,但是,如果其他任何選項在列表1中選擇你要移動到新的代碼塊,並且必須在列表2中選擇一個選項,如果您在清單1和列表2中取消了,那麼您就搞砸了。

關於我在這裏失蹤的任何想法?

回答

0

使用此代碼的工作:如果selectedTask包含「1」,則

5

{ }在AppleScript中創建一個列表,因此當您設置selectedTask時,您將結果從choose from list放入另一個列表中。當您嘗試將結果與{"1"}進行比較時,它實際上是{{"1"}},因此它不相等。使用括號()代替分組。

+1

我仍然不能讓它進入if塊

 if selectedTask is equal to {{"1"}} then \t \t display dialog selectedTask \t else 
如果選擇1應該進入,如果塊爲任務和停止,當我運行它,它還是同時運行if語句的一部分 – 2009-08-31 00:39:36

+0

您正在將問題修復在錯誤的地方。將set selectedTask中的{}替換爲{從列表中選擇WhatDoUWantToDoList,並提示「現在選擇你的任務!!!」沒有多個選擇允許}'with()。 – 2009-08-31 19:51:24

0

從列表中選擇,因爲多選總是會返回一個數組。其基本思想是:

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