gpt4 book ai didi

macos - 如何在 Mac/UNIX Shell 脚本的 osascript 提示对话框中隐藏密码

转载 作者:行者123 更新时间:2023-12-01 21:56:37 26 4
gpt4 key购买 nike

我正处于设计脚本的最后阶段,该脚本可自动执行可供多人使用的 Active Directory 绑定(bind)。因此,我需要提示输入用户名和密码。我已成功创建提示,但想找到某种方法来防止密码显示在要求输入密码的对话框中(这将远程完成,我不希望密码可见)。

它可以变成星星、点,根本不显示,任何东西,我只需要它不以视觉方式显示,但仍然能够传递到 dsconfigad 命令。

我已经测试了脚本本身,它可以工作,这是我让它生效所需的最后一部分。

(请原谅这里有任何额外的评论,我从很多不同的来源将其拼凑在一起)

#!/bin/bash

while :; do # Loop until valid input is entered or Cancel is pressed.
user=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network user name:" default answer ""' -e 'text returned of result' 2>/dev/null)
if (( $? )); then exit 1; fi # Abort, if user pressed Cancel.
user=$(echo -n "$user" | sed 's/^ *//' | sed 's/ *$//') # Trim leading and trailing whitespace.
if [[ -z "$user" ]]; then
# The user left the project name blank.
osascript -e 'Tell application "System Events" to display alert "You must enter a user name; please try again." as warning' >/dev/null
# Continue loop to prompt again.
else
# Valid input: exit loop and continue.
break
fi
done

while :; do # Loop until valid input is entered or Cancel is pressed.
netpass=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" default answer ""' -e 'text returned of result' 2>/dev/null)
if (( $? )); then exit 1; fi # Abort, if user pressed Cancel.
netpass=$(echo -n "$netpass" | sed 's/^ *//' | sed 's/ *$//') # Trim leading and trailing whitespace.
if [[ -z "$netpass" ]]; then
# The user left the project name blank.
osascript -e 'Tell application "System Events" to display alert "You must enter a password; please try again." as warning' >/dev/null
# Continue loop to prompt again.
else
# Valid input: exit loop and continue.
break
fi
done

MACNAME=$(scutil --get ComputerName)

sudo dsconfigad -add DOMAIN \
-username $user \
-password $netpass \
-computer $MACNAME \
-mobile disable \
-mobileconfirm disable \
-localhome enable \
-useuncpath enable \
-shell /bin/bash \
-ou OU=Macs,CN=Computers,DC=corp,DC=DOMAIN,DC=net \
-force \
-localpassword LOCALPASS \
-groups "GROUPS"

#sudo rm -- "$0"

最佳答案

使用隐藏答案。链接:

https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW12

osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" with hidden answer default answer ""' -e 'text returned of result' 2>/dev/null

关于macos - 如何在 Mac/UNIX Shell 脚本的 osascript 提示对话框中隐藏密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25575635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com