How to hide password from osascript prompted dialog from Mac / UNIX Script shell
I am at the last stage of designing a script to automate an Active Directory binding to be used by multiple people. Because of this, I need to prompt for a username and password. I successfully created a request, but I want to find a way to prevent the password from appearing in the password prompt dialog (this will be done remotely, I don't want the password to be visible).
It can be turned into stars, dots, and not anything at all, I just need NOT to show it visually, but you can still pass the dsconfigad command.
I've tested the script myself and it works and this is the last snippet I need to make it live.
(Sorry for additional comments, I put this together from various sources)
#!/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"
+3
source to share