0

到目前为止,我有以下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,您搞砸了。

关于我在这里缺少什么的任何想法?

4

3 回答 3

5

{ }在 AppleScript 中创建一个列表,因此当您设置 时selectedTask,您将结果从choose from list放入另一个列表中。当您尝试将结果与 进行比较时{"1"},它实际上是{{"1"}},因此它不相等。

改为使用括号( )进行分组。

于 2009-08-30T02:50:52.103 回答
0

使用此代码有效:如果 selectedTask 包含“1”,则

于 2009-08-31T00:51:54.347 回答
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
于 2009-10-08T18:45:40.263 回答