问题
A fairly basic problem here, but I have no AppleScript experience.
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?
The essence of what I want:
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
way of doing it?
回答1:
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
来源:https://stackoverflow.com/questions/37196822/applescript-how-to-return-to-previous-dialog-list