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

AppleScript:如何返回到上一个对话框/列表?,applescript,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 "Serve

这是一个相当基本的问题,但我没有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

怎么做?

我相信这就是你想要的。我尽量不修改您的原始代码,但我认为您可以在其中改进一些内容。例如,您允许多个选择,但如果他们同时选择a和B,您没有处理方法

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

我相信这就是你想要的。我尽量不修改您的原始代码,但我认为您可以在其中改进一些内容。例如,您允许多个选择,但如果他们同时选择a和B,您没有处理方法

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

我相信你要找的是递归。为你的代码创建一个方法,在这个方法中,如果答案是“Back”,再次调用这个方法。我相信你正在寻找的是递归。为您的代码创建一个方法,如果答案为“返回”,请在该方法中再次调用该方法。谢谢!工作得很有魅力!chooseServer()上的
成功了。但我看不出有必要跑?没有它还能工作吗?至于多重选择;我用自己的方式做事从来没有遇到过任何问题。我有12种不同的坐骑。我猜它只是运行if的顺序?否则我将如何处理多个选择?您描述的错误上的
不是首选。如果失败,我已经收到通知。谢谢!工作得很有魅力!chooseServer()上的
成功了。但我看不出有必要跑?没有它还能工作吗?至于多重选择;我用自己的方式做事从来没有遇到过任何问题。我有12种不同的坐骑。我猜它只是运行if的顺序?否则我将如何处理多个选择?您描述的错误上的
不是首选。如果失败,我已经收到通知。