AppleScript:如何返回上一个对话框/列表? [英] AppleScript: How to return to previous dialog/list?

查看:18
本文介绍了AppleScript:如何返回上一个对话框/列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

A fairly basic problem here, but I have no AppleScript experience.

制作一个包含多项选择和 if/then 条件的列表.选择显示一个带有一个按钮的对话框,将您带回列表.我知道 AppleScript 中没有go to line",那么最好的方法是什么?

Made a list with multiple selections and if/then conditions. Made a selection to display a dialog with one button that takes you back to the list. I know theres no "go to line" in AppleScript, so what would be the best way to do this?

我想要的本质:

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

我如何回到这里的列表?我无法重写从列表中选择".有没有

How do I go back to the list here? I cant rewrite the "choose from list". Is there a

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

怎么做?

推荐答案

我相信这就是您所追求的.我尽量不大量修改您的原始代码,但我认为您可以改进其中的一些内容.例如,您允许进行多项选择,但如果他们同时选择 A 和B.

I believe this is what you're after. I tried not to modify your original code much, but I think there are some things you could improve in it. For example you're allowing multiple selections, but you don't have a way of handling if they select both 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

这篇关于AppleScript:如何返回上一个对话框/列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆