我想在AppleScript中创建一个类似于以下对话框的输入框:
除了锁左上方没有图片。
此外,我需要能够保存两个输入。
我知道我可以使用tell application "System Events" to display dialog "blah blah" default answer "" end tell
,但是我找不到找到具有多个标记字段的方法。
本机上,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
和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:"
。