我一直在寻找AppleScript: How to return to previous dialog/list?,它给了我一个很好的起点,但是解决方案只深入了一个对话框列表。我将如何在树中拥有多个列表,其中的“后退”按钮只会使您返回上一级,而不是一直返回到顶层。
我一直在阅读AppleScript Handlers,但是我不知道如何拥有多个。
此外,我的代码中出现错误。如果我从第一个列表中取消,则对话框将按预期关闭。但是,如果我进入下一个对话框“列表”,然后按“上一步”,然后按“取消”,我将收到错误“无法得到错误的项目1”。来自 false
的 item 1个中的-1728号on run
chooseLetter()
end run
on chooseLetter()
set preparedResponse to "" -- initialize the variable
set prList to choose from list {"Alpha", "Beta", "Gamma", "Delta"} with title "Greek Alphabet" with prompt "Alphabet Characters:" default items {""}
if prList is false then return
set preparedResponse to item 1 of prList
set currentPR to "" -- initialize the variable
if preparedResponse is "Alpha" then
set articleList to choose from list {"Alpha One", "Alpha Two", "Alpha Three", "Alpha Four"} with title "Alpha Title" with prompt "Alpha Choices:" OK button name "Next" cancel button name "Back"
if articleList is false then chooseLetter()
set currentPR to item 1 of articleList
else if preparedResponse is "Beta" then
set articleList to choose from list {"Beta One", "Beta Two", "Beta Three", "Beta Four", "Beta Five"} with title "Beta Title" with prompt "Beta Choices:" default items {"Beta One"} OK button name "Next" cancel button name "Back"
if articleList is false then chooseLetter()
set currentPR to item 1 of articleList
else if preparedResponse is "Gamma" then
set articleList to choose from list {"Epsilon", "Zeta"} with title "Gamma Title" with prompt "Gamma Choices:" default items {"Epsilon"} OK button name "Next" cancel button name "Back"
if articleList is false then chooseLetter()
set currentPR to item 1 of articleList
else if preparedResponse is "Delta" then
set articleList to choose from list {"Delta One", "Delta Two", "Delta Three"} with title "Delta Title" with prompt "Delta Choices:" default items {"Delta Three"} OK button name "Next" cancel button name "Back"
if articleList is false then chooseLetter()
set currentPR to item 1 of articleList
end if
set letterGroup to preparedResponse
set prChoice to currentPR
set prResponseCode to "" -- initialize the variable
#Alpha
if letterGroup is "Alpha" and prChoice is "Alpha One" then
set prResponseCode to "α 1000"
else if letterGroup is "Alpha" and prChoice is "Alpha Two" then
set prResponseCode to "α 1001"
else if letterGroup is "Alpha" and prChoice is "Alpha Three" then
set categoryList to choose from list {"Eta", "Theta"} with title "Alpha Three Title" with prompt "Alpha Three Choices:" OK button name "Next" cancel button name "Back"
if categoryList is false then chooseLetter()
set categoryError to item 1 of categoryList
if categoryError is "Eta" then
set the clipboard to "Eta is the seventh letter of the Greek alphabet. Originally denoting a consonant /h/, its sound value in the classical Attic dialect of Ancient Greek was a long vowel, raised to [i] in hellenistic Greek, a process known as iotacism."
else if categoryError is "Theta" then
set the clipboard to "Theta is the eighth letter of the Greek alphabet, derived from the Phoenician letter Teth. In the system of Greek numerals it has the value 9."
end if
set prResponseCode to "α 1002"
else if letterGroup is "Alpha" and prChoice is "Alpha Four" then
set prResponseCode to "α 1003"
# Beta
else if letterGroup is "Beta" and prChoice is "Beta One" then
set prResponseCode to "β 2000"
else if letterGroup is "Beta" and prChoice is "Beta Two" then
set prResponseCode to "β 2001"
else if letterGroup is "Beta" and prChoice is "Beta Three" then
set prResponseCode to "β 2002"
else if letterGroup is "Beta" and prChoice is "Beta Four" then
set prResponseCode to "β 2003"
else if letterGroup is "Beta" and prChoice is "Beta Five" then
set prResponseCode to "β 2004"
# Gamma
else if letterGroup is "Gamma" then
set misrouteGroup to "" -- initialize the variable
if prChoice is "Epsilon" then
set misrouteList to choose from list {"Epsilon One", "Epsilon Two", "Epsilon Three", "Epsilon Four"} with title "Epsilon Title" with prompt "Epsilon Choices:" OK button name "Next" cancel button name "Back"
if misrouteList is false then chooseLetter()
set misrouteGroup to item 1 of misrouteList
else if prChoice is "Zeta" then
set misrouteList to choose from list {"Zeta One", "Zeta Two", "Zeta Three", "Zeta Four", "Zeta Five", "Zeta Six"} with title "Zeta Title" with prompt "Zeta Choices:" OK button name "Next" cancel button name "Back"
if misrouteList is false then chooseLetter()
set misrouteGroup to item 1 of misrouteList
end if
if prChoice is "Epsilon" and misrouteGroup is "Epsilon One" then
set prResponseCode to "ε 5000"
else if prChoice is "Epsilon" and misrouteGroup is "Epsilon Two" then
set prResponseCode to "ε 5001"
else if prChoice is "Epsilon" and misrouteGroup is "Epsilon Three" then
set prResponseCode to "ε 5002"
else if prChoice is "Epsilon" and misrouteGroup is "Epsilon Four" then
set prResponseCode to "ε 5003"
else if prChoice is "Zeta" and misrouteGroup is "Zeta One" then
set prResponseCode to "ζ 6000"
else if prChoice is "Zeta" and misrouteGroup is "Zeta Two" then
set prResponseCode to "ζ 6001"
else if prChoice is "Zeta" and misrouteGroup is "Zeta Three" then
set prResponseCode to "ζ 6002"
else if prChoice is "Zeta" and misrouteGroup is "Zeta Four" then
set prResponseCode to "ζ 6003"
else if prChoice is "Zeta" and misrouteGroup is "Zeta Five" then
set prResponseCode to "ζ 6004"
else if prChoice is "Zeta" and misrouteGroup is "Zeta Six" then
set prResponseCode to "ζ 6005"
end if
# Delta
else if letterGroup is "Delta" and prChoice is "Delta One" then
set prResponseCode to "δ 4000"
else if letterGroup is "Delta" and prChoice is "Delta Two" then
set prResponseCode to "δ 4001"
else if letterGroup is "Delta" and prChoice is "Delta Three" then
set prResponseCode to "δ 4002"
end if
set prResponseCode to "Classic " & prResponseCode
set textToType to prResponseCode
end chooseLetter
从对话框列表“ Alpha三种选择:”中,我希望能够返回到列表“ Alpha Choices:”,并且“ Epsilon Choices”应回到“ Gamma Choices”。现在,所有内容都回到顶部级别“字母字符:”
答案 0 :(得分:1)
错误Can’t get item 1 of false." number -1728 from item 1 of false
很明显。
首先,规则是:return
语句退出当前作用域。在on run
处理程序中,由于脚本位于顶层,因此它将中止脚本。
到目前为止很好。
无论如何,您都递归调用chooseLetter()
,因此在行Cancel
被调用之后,继续按chooseLetter()
按钮(或其名称)。
我建议与处理程序一起使用。处理程序代表单个作用域。
答案 1 :(得分:0)
我能够弄清楚如何使其工作。我对必须使用error number -128
并不感到兴奋,但除此之外,整个过程都很好。
可能有更优雅的编写方式,但这对我来说是一个好的开始。
on run
global preparedResponse, prResponseCode, articleList
set prResponseFinal to "" -- intialize the variable
set textToType to "" -- intialize the variable
chooseLetter()
activate application "TextEdit"
tell application "System Events" to tell process "TextEdit"
keystroke textToType
end tell
end run
on chooseLetter()
set prList to "" -- intialize the variable
set prList to choose from list {"Alpha", "Beta", "Gamma", "Delta"} with title "Greek Alphabet" with prompt "Alphabet Characters:" default items {""}
if prList is false then
error number -128
else
set preparedResponse to item 1 of prList
end if
set letterGroup to preparedResponse
set prResponseCode to "" -- initialize the variable
if preparedResponse is "Alpha" then chooseAlpha()
if preparedResponse is "Beta" then chooseBeta()
if preparedResponse is "Gamma" then chooseGamma()
if preparedResponse is "Delta" then chooseDelta()
end chooseLetter
# Alpha
on chooseAlpha()
global preparedResponse, prResponseCode, articleList, textToType
set preparedResponse to "" -- intialize the variable
set prResponseCode to "" -- intialize the variable
set articleList to "" -- initialize the variable
set articleList to choose from list {"Alpha One", "Alpha Two", "Alpha Three", "Alpha Four"} with title "Alpha Title" with prompt "Alpha Choices:" OK button name "Next" cancel button name "Back"
if articleList is false then
chooseLetter()
else
set preparedResponse to item 1 of articleList
end if
if preparedResponse is "Alpha One" then set prResponseCode to "α 1000"
if preparedResponse is "Alpha Two" then set prResponseCode to "α 1001"
if preparedResponse is "Alpha Three" then chooseAlpha2()
if preparedResponse is "Alpha Four" then set prResponseCode to "α 1003"
set prResponseFinal to "Classic " & prResponseCode
set textToType to prResponseFinal
end chooseAlpha
# Alpha2
on chooseAlpha2()
global preparedResponse, prResponseCode, articleList
set preparedResponse to "" -- intialize the variable
set prResponseCode to "" -- initialize the variable
set categoryList to "" -- initialize the variable
set categoryList to choose from list {"Eta", "Theta"} with title "Alpha Three Title" with prompt "Alpha Three Choices:" OK button name "Next" cancel button name "Back"
if categoryList is false then
chooseAlpha()
else
set preparedResponse to item 1 of categoryList
end if
if preparedResponse is "Eta" then
set the clipboard to "Eta is the seventh letter of the Greek alphabet. Originally denoting a consonant /h/, its sound value in the classical Attic dialect of Ancient Greek was a long vowel, raised to [i] in hellenistic Greek, a process known as iotacism."
set prResponseCode to "η 7000"
end if
if preparedResponse is "Theta" then
set the clipboard to "Theta is the eighth letter of the Greek alphabet, derived from the Phoenician letter Teth. In the system of Greek numerals it has the value 9."
set prResponseCode to "θ 8000"
end if
end chooseAlpha2
# Beta
on chooseBeta()
global preparedResponse, prResponseCode, articleList, textToType
set preparedResponse to "" -- intialize the variable
set prResponseCode to "" -- intialize the variable
set articleList to "" -- initialize the variable
set articleList to choose from list {"Beta One", "Beta Two", "Beta Three", "Beta Four", "Beta Five"} with title "Beta Title" with prompt "Beta Choices:" default items {"Beta One"} OK button name "Next" cancel button name "Back"
if articleList is false then
chooseLetter()
else
set preparedResponse to item 1 of articleList
end if
if preparedResponse is "Beta One" then set prResponseCode to "β 2000"
if preparedResponse is "Beta Two" then set prResponseCode to "β 2001"
if preparedResponse is "Beta Three" then set prResponseCode to "β 2002"
if preparedResponse is "Beta Four" then set prResponseCode to "β 2003"
if preparedResponse is "Beta Five" then set prResponseCode to "β 2004"
set prResponseFinal to "Classic " & prResponseCode
set textToType to prResponseFinal
end chooseBeta
# Gamma
on chooseGamma()
global preparedResponse, prResponseCode, articleList
set preparedResponse to "" -- intialize the variable
set prResponseCode to "" -- intialize the variable
set articleList to "" -- initialize the variable
set articleList to choose from list {"Epsilon", "Zeta"} with title "Gamma Title" with prompt "Gamma Choices:" default items {"Epsilon"} OK button name "Next" cancel button name "Back"
if articleList is false then
chooseLetter()
else
set preparedResponse to item 1 of articleList
end if
if preparedResponse is "Epsilon" then chooseGamma2()
if preparedResponse is "Zeta" then chooseGamma3()
end chooseGamma
# Gamma2
on chooseGamma2()
global preparedResponse, prResponseCode, articleList, textToType
set preparedResponse to "" -- intialize the variable
set prResponseCode to "" -- intialize the variable
set articleList to "" -- initialize the variable
set misrouteList to choose from list {"Epsilon One", "Epsilon Two", "Epsilon Three", "Epsilon Four"} with title "Epsilon Title" with prompt "Epsilon Choices:" OK button name "Next" cancel button name "Back"
if misrouteList is false then
chooseGamma()
else
set preparedResponse to item 1 of misrouteList
end if
if preparedResponse is "Epsilon One" then set prResponseCode to "ε 5000"
if preparedResponse is "Epsilon Two" then set prResponseCode to "ε 5001"
if preparedResponse is "Epsilon Three" then set prResponseCode to "ε 5002"
if preparedResponse is "Epsilon Four" then set prResponseCode to "ε 5003"
set prResponseFinal to "Classic " & prResponseCode
set textToType to prResponseFinal
end chooseGamma2
# Gamma3
on chooseGamma3()
global preparedResponse, prResponseCode, articleList, textToType
set preparedResponse to "" -- intialize the variable
set prResponseCode to "" -- intialize the variable
set articleList to "" -- initialize the variable
set misrouteList to choose from list {"Zeta One", "Zeta Two", "Zeta Three", "Zeta Four", "Zeta Five", "Zeta Six"} with title "Zeta Title" with prompt "Zeta Choices:" OK button name "Next" cancel button name "Back"
if misrouteList is false then
chooseGamma()
else
set preparedResponse to item 1 of misrouteList
end if
if preparedResponse is "Zeta One" then set prResponseCode to "ζ 6000"
if preparedResponse is "Zeta Two" then set prResponseCode to "ζ 6001"
if preparedResponse is "Zeta Three" then set prResponseCode to "ζ 6002"
if preparedResponse is "Zeta Four" then set prResponseCode to "ζ 6003"
if preparedResponse is "Zeta Five" then set prResponseCode to "ζ 6004"
if preparedResponse is "Zeta Six" then set prResponseCode to "ζ 6005"
set prResponseFinal to "Classic " & prResponseCode
set textToType to prResponseFinal
end chooseGamma3
# Delta
on chooseDelta()
global preparedResponse, prResponseCode, articleList, textToType
set preparedResponse to "" -- intialize the variable
set prResponseCode to "" -- intialize the variable
set articleList to "" -- initialize the variable
set articleList to choose from list {"Delta One", "Delta Two", "Delta Three"} with title "Delta Title" with prompt "Delta Choices:" default items {"Delta Three"} OK button name "Next" cancel button name "Back"
if articleList is false then
chooseLetter()
else
set preparedResponse to item 1 of articleList
end if
if preparedResponse is "Delta One" then set prResponseCode to "δ 4000"
if preparedResponse is "Delta Two" then set prResponseCode to "δ 4001"
if preparedResponse is "Delta Three" then set prResponseCode to "δ 4002"
set prResponseFinal to "Classic " & prResponseCode
set textToType to prResponseFinal
end chooseDelta