passwords - 使用 AppleScript 制作用户名和密码输入框

标签 passwords applescript inputbox

我想在 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

对话框将如下所示:

enter image description here

设置 Pashua 概述

注意:这是一个简化的概述;有关完整说明,请参阅 Read me.htmlDocumentation.html在下载的光盘镜像中。
  • http://www.bluem.net/en/mac/pashua/ 下载并安装光盘镜像
  • 地点 Pashua.app/Applications , ~/Applications , 或者 - 在紧要关头 - 在与调用脚本相同的文件夹中。
  • Pashua.app是呈现对话框的应用程序(当对话框打开时,菜单栏显示 Pashua )。
  • showDialog 复制绑定(bind)代码(2 个短处理程序,getPashuaPathExamples/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:" .
  • 或者,直接从 GitHub 存储库获取最新的绑定(bind)代码:https://github.com/BlueM/Pashua-Binding-AppleScript
  • 关于passwords - 使用 AppleScript 制作用户名和密码输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28756565/

    相关文章:

    linux - 让AppleScript发送电子邮件,然后通过shell脚本重新启动计算机?

    vb.net - 是否可以更改 vb.net 中的输入框图标?

    excel - 当提示用户在 Excel 中使用输入框选择范围时,强制 VBA 显示当前选定的单元格

    excel - 取消时Application.InputBox错误424

    linux - 跨车队的凭证分发/存储

    excel - 在 Excel 工作簿中的所有工作表上迭代 Applescript

    c# - 是否可以将密码输入字符串确定为明文或散列?

    Java 在新终端 (mac osx) 中开始运行命令 - 进程生成器未正确运行 osascript

    python - 如何以编程方式在 django 1.7.6 中触发密码重置电子邮件?

    database - 在数据库中存储密码的最佳方式