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

Pat*_*ook 5 passwords applescript inputbox

我想在 AppleScript 中创建一个与此完全相同的对话框输入框:

除了没有锁左上角的图片。

另外,我需要能够保存两个输入。

我知道我可以使用,tell application "System Events" to display dialog "blah blah" default answer "" end tell但我找不到一种方法来拥有多个和标记的字段。

mkl*_*nt0 4

从 OSX 10.10 开始,AppleScript 本身不提供此功能

\n\n

要查看支持哪些 GUI 操作,请检查User Interaction标准添加的字典套件(可从viaStandardAdditions.def访问)。Script Editor.appFile > Open Dictionary... > StandardAdditions.osax

\n\n

最接近的近似是单个输入字段对话框- 仅提示输入密码 - 如下(您已经在问题中注意到的限制,但只是为了说明如何提示输入密码以及如何使用自定义按钮):

\n\n
display dialog \xc2\xac\n    "Installer is ..." default answer \xc2\xac\n    "" buttons {"Cancel", "Install Software"} \xc2\xac\n    default button 2 \xc2\xac\n    with hidden answer\n
Run Code Online (Sandbox Code Playgroud)\n\n

为了得到你想要的,你需要一个第三方库,比如Pashua

\n\n

以下是如何在 Pashua 中定义请求的对话框并处理返回值:

\n\n
# Define the dialog using a textual definition similar to a properties file.\nset dlgDef to "\n# Window title (if you don\'t set one explicitly (even if empty), it\'ll be \'Pashua\')\n*.title = \n\n# Add the hint (static text).\nst.type = text\nst.text = Installer is trying to install new software. Type your password to allow this.\n\n# Add the username field.\ntfn.type = textfield\ntfn.label = Name:\n\n# Add the password field.\ntfp.type = password\ntfp.label = Password:\n\n# Add the buttons.\ncb.type = cancelbutton\ndb.type = defaultbutton\ndb.label = Install Software\n"\n\n# Show the dialog. \n# Return value is a record whose keys are the element names from the dialog\n# definition (e.g., "tfn" for the  usernam text field) and whose\n# values are the values entered (for input fields) or \n# whether a given button was clicked or not ("1" or "0")\nset theResult to showDialog(dlgDef, "")\n\n# Process the returned values.\nif cb of theResult is "1" then\n    display alert "User canceled the dialog."\nelse\n    display alert "name=[" & tfn of theResult & "]; password=[" & tfp of theResult & "]"\nend if\n
Run Code Online (Sandbox Code Playgroud)\n\n

该对话框将如下所示:

\n\n

在此输入图像描述

\n\n
\n\n

设置 Pahua 的概述

\n\n

注意:这是一个简化的概述;有关完整说明,请参阅下载的光盘映像中的Read me.html和。Documentation.html

\n\n
    \n
  • 从http://www.bluem.net/en/mac/pashua/下载并安装光盘映像
  • \n
  • Pashua.app、或 - 必要时 - 放在与调用脚本相同的文件夹中。\n\ /Applicationsn~/Applications
      \n
    • Pashua.app是呈现对话框的应用程序(当对话框打开时,菜单栏显示Pashua)。
    • \n
  • \n
  • 从以下位置复制绑定代码(2 个短处理程序showDialoggetPashuaPathExamples/AppleScript/Pashua.scpt复制到脚本中。\n\n
      \n
    • 注意:由于撰写本文时存在错误,您必须对处理程序进行小修正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:"
    • \n
    • 或者,直接从 GitHub 存储库获取最新的绑定代码:https://github.com/BlueM/Pashua-Binding-AppleScript
    • \n
  • \n
\n