AppleScript:如何返回上一个对话框/列表?

时间:2016-05-12 20:28:17

标签: applescript

这是一个相当基本的问题,但我没有AppleScript经验。

制作一个包含多个选项和if / then条件的列表。选择显示一个对话框,其中包含一个按钮,可以将您带回列表。我知道AppleScript中没有“走线”,那么最好的方法是什么呢?

我想要的本质:

set A to "smb://XXX"
set B to "smb://XXX"
set servers to {"A", "B"}

set chosen to (choose from list servers with title "Servers" with prompt "Connect to:" OK button name "Connect" cancel button name "Abort" with multiple selections allowed) as text

try
if (text of chosen) is "A" then
    mount volume (A as string)
end if

if (text of chosen) is "B" then
        beep
        display dialog "Not available yet" as text with icon stop with title "Error" buttons {"Back"} default button 1

如何返回此处的列表? 我不能改写“从列表中选择”。有没有

if result = {button returned:"Back"} then

这样做的方式?

1 个答案:

答案 0 :(得分:0)

我相信这就是你所追求的。我试着不要修改你的原始代码,但我认为你可以在其中改进一些东西。例如,您允许进行多项选择,但如果他们同时选择A& A,则您无法处理。乙

on run
    chooseServer()
end run

on chooseServer()
    set A to "smb://XXX"
    set B to "smb://XXX"
    set servers to {"A", "B"}

    set chosen to (choose from list servers with title "Servers" with prompt "Connect to:" OK button name "Connect" cancel button name "Abort" with multiple selections allowed) as text

    if (text of chosen) is "A" then
        try
            mount volume (A as string)
        on error e
            display dialog e giving up after 5
        end try
    else if (text of chosen) is "B" then
        beep
        if button returned of (display dialog "Not available yet" as text with icon stop with title "Error" buttons {"Back"} default button 1) = "Back" then
            chooseServer() -- recursive call
        end if
    end if
end chooseServer