AppleScript:“从列表中选择”中的多个按钮

问题描述 投票:0回答:3

我有一个脚本,可以让用户从列表中的不同选项中进行选择。我想要有三个按钮;确定、取消和帮助(显示带有指导的对话框)。

但是,我似乎无法在列表中使用“buttons”参数。

那么如何添加其他按钮?(使用自定义名称,显示对话框)

当前脚本:

set MyList to {"A", "B", "C"}

set Chosen to 
    (choose from list MyList with title "Connect to" 
    with prompt "What do you want to connect to?" 
    OK button name "Connect" cancel button name "Abort" ---and help
    with multiple selections allowed) as text
applescript applescript-objc
3个回答
1
投票

不幸的是

choose from list
仅支持两个按钮。

替代方案是(第二个)标准对话框,用于打开列表对话框或带有自定义对话框窗口的 AppleScriptObjC 应用程序。


0
投票

虽然

choose from list
仅支持两个按钮,但您可以使用 AppleScriptObjC 创建非常丰富的警报/对话框。我建议从 Shane Stanley 的 free Myriad Tables Lib 开始。这是一个例子:

要了解更多信息,请阅读 Shane 价值 15 美元的优秀书籍 Everyday AppleScriptObjC 中的第 26 章:更丰富的接口,可在此处获取。您还可以查看同一页面上的对话框工具包。因为 Cocoa 警报和对话框提供了“附件视图”,所以您可以在其中放置许多附加控件。


0
投票

这里有 2 个插入“菜单栏”的普通示例,它在标准“从列表中选择”菜单中提供了附加选项...

[1] 这会激活顶部菜单项的二级菜单。

return my choosefromList(lst)
property lst : ("
1
2
3
")
property prev : {}
on choosefromList(lst)
repeat
repeat
repeat while lst begins with linefeed or lst begins with return
set lst to text 2 thru -1 of lst
end repeat
repeat while lst ends with linefeed or lst ends with return
set lst to text 1 thru -2 of lst
end repeat
set mnuBar to "_______________________________________/EDIT\"
set chosn to (choose from list {mnuBar} & (paragraphs of lst) default items prev with multiple selections allowed)
if class of chosn is boolean then
set msg to "User canceled."
say msg without waiting until completion
return msg
end if
if chosn begins with mnuBar then
if (count of chosn) > 1 then set chosn to items 2 thru -1 of chosn --keep selection
set msg to "Edit menu items:"
say msg without waiting until completion
set lst to text returned of (display dialog msg default answer return & lst & return)
set prev to chosn
else
set prev to chosn
exit repeat
end if
end repeat
repeat with chos in chosn
say chos without waiting until completion
display dialog contents of chos
end repeat
end repeat
end choosefromList

[2] 这会激活顶部菜单项的下拉菜单。

return my choosefromList(lst)
property lst : ("
1
2
3
")
property prev : {}
property mnu2 : {}
property dropdown : false
on choosefromList(lst)
repeat
repeat
---------------------MENU 1---------------------
set mnuBar to "                                                                                    Preferences ⚙️"
set chosn to (choose from list {mnuBar} & mnu2 & (paragraphs 2 thru -2 of lst) default items prev with multiple selections allowed)
if class of chosn is boolean then
set msg to "User canceled."
say msg without waiting until completion
return msg
end if
if chosn begins with mnuBar then
if (count of chosn) > 1 then set prev to items 2 thru -1 of chosn --keep selection
------------------DROPDOWN HANDLER---------------------
set dropdown to item (1 + (dropdown as integer)) of {true, false} --toggled if dropdown then say "preferences on" without waiting until completion set mnu2 to {" A.", " B.", " C."} else say "preferences off" without waiting until completion set mnu2 to {} end if ---------------------------------------------------------------- else set prev to chosn exit repeat end if end repeat ---------------------MAIN MENU HANDLER--------------------- repeat with chos in chosn say chos without waiting until completion display dialog contents of chos end repeat ------------------------------------------------------------------- end repeat end choosefromList

© www.soinside.com 2019 - 2024. All rights reserved.