2009-08-30 45 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