代码之家  ›  专栏  ›  技术社区  ›  Chris Hough

在AppleScript中列出值?

  •  0
  • Chris Hough  · 技术社区  · 16 年前

    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中取消,则会出错。

    你知道我在这里遗漏了什么吗?

    3 回复  |  直到 16 年前
        1
  •  5
  •   Nicholas Riley    16 年前

    { } 在AppleScript中创建一个列表,因此 selectedTask ,您将从 choose from list 进入另一个列表。当您尝试将结果与 {"1"} {{"1"}} ,所以这是不平等的。

    使用括号 ( ) 改为分组。

        2
  •  0
  •   Chris Hough    16 年前

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

        3
  •  0
  •   cosmin    16 年前

    “从列表中选择”将始终返回一个数组,因为可以进行多次选择。基本思想是:

    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