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

问题描述 投票:4回答:1

我想在AppleScript中创建一个类似于以下对话框的输入框:“

除了锁左上方没有图片。

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

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

passwords applescript username inputbox
1个回答
3
投票

本机上,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.htmlDocumentation.html

    http://www.bluem.net/en/mac/pashua/下载并安装光盘映像
  • Pashua.app放置在/Applications~/Applications中,或-紧紧放在-与调用脚本相同的文件夹中。
    • [Pashua.app是呈现对话框的应用程序(对话框打开时,菜单栏显示Pashua)。
  • 将绑定代码(2个短处理程序,showDialoggetPashuaPath)从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:"
  • 或者,直接从GitHub存储库中获取最新的绑定代码:https://github.com/BlueM/Pashua-Binding-AppleScript
  • © www.soinside.com 2019 - 2024. All rights reserved.