我想在 AppleScript 中制作一个看起来完全一样的对话框输入框:
除了锁的左上角没有图片。
此外,我需要能够保存两个输入。
我知道我可以使用 tell application "System Events" to display dialog "blah blah" default answer "" end tell
但我找不到拥有多个标签字段的方法。
最佳答案
native , AppleScript 从 OSX 10.10 开始不提供此功能.
查看支持哪些 GUI 操作 ,查看User Interaction
标准添加字典套件( StandardAdditions.def
,可从 Script Editor.app
通过 File > Open Dictionary... > StandardAdditions.osax
访问)。
最接近的近似值是单个输入字段对话框 - 仅提示输入密码 - 如下(您已经在问题中指出了一个限制,但只是为了说明如何提示输入密码以及如何使用自定义按钮):
display dialog ¬
"Installer is ..." default answer ¬
"" buttons {"Cancel", "Install Software"} ¬
default button 2 ¬
with hidden answer
要得到你想要的,您需要第三方库,例如 Pashua .
以下是在 Pashua 中定义请求的对话框并处理返回值的方法:
# Define the dialog using a textual definition similar to a properties file.
set dlgDef to "
# Window title (if you don't set one explicitly (even if empty), it'll be 'Pashua')
*.title =
# Add the hint (static text).
st.type = text
st.text = Installer is trying to install new software. Type your password to allow this.
# Add the username field.
tfn.type = textfield
tfn.label = Name:
# Add the password field.
tfp.type = password
tfp.label = Password:
# Add the buttons.
cb.type = cancelbutton
db.type = defaultbutton
db.label = Install Software
"
# Show the dialog.
# Return value is a record whose keys are the element names from the dialog
# definition (e.g., "tfn" for the usernam text field) and whose
# values are the values entered (for input fields) or
# whether a given button was clicked or not ("1" or "0")
set theResult to showDialog(dlgDef, "")
# Process the returned values.
if cb of theResult is "1" then
display alert "User canceled the dialog."
else
display alert "name=[" & tfn of theResult & "]; password=[" & tfp of theResult & "]"
end if
对话框将如下所示:
设置 Pashua 概述
注意:这是一个简化的概述;有关完整说明,请参阅
Read me.html
和 Documentation.html
在下载的光盘镜像中。Pashua.app
在 /Applications
, ~/Applications
, 或者 - 在紧要关头 - 在与调用脚本相同的文件夹中。Pashua.app
是呈现对话框的应用程序(当对话框打开时,菜单栏显示 Pashua
)。 showDialog
复制绑定(bind)代码(2 个短处理程序,getPashuaPath
和 Examples/AppleScript/Pashua.scpt
)进入你的脚本。getPashuaPath
应用一个小的更正。 : 替换行 return (path to applications folder from system domain as text) & "Pashua.app"
与 return (path to applications folder from system domain as text) & "Pashua.app:"
. 关于passwords - 使用 AppleScript 制作用户名和密码输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28756565/